此 'let' 之后的块未完成,尽管从函数返回值但 F# 错误
The block following this 'let' is unfinished, F# error despite returning the value from function
| Log (message, ack) ->
let CreateEventSourcingConnection() =
task {
let connection =
let ipEndPoint = IPEndPoint(IPAddress.Loopback, 1113)
EventStoreConnection.Create(ipEndlPoint)
do! connection.ConnectAsync()
return connection
}
let AddEventToStreamAsync (connection: IEventStoreConnection) streamName eventName message =
task {
let serializedEventData =
message
|> JsonConvert.SerializeObject
|> Encoding.UTF8.GetBytes
let event = EventData(Guid.NewGuid(), eventName, true, serializedEventData, null)
let! _ = connection.AppendToStreamAsync(streamName, int64 ExpectedVersion.Any, event)
()
}
错误:
The block following this 'let' is unfinished. Every code block is an expression and must have a result. 'let' cannot be the final code element in a block. Consider giving this block an explicit result.
我试过在定义它们之后调用这些函数。我也检查了我的缩进,我想应该没问题。我知道我需要 return 函数的值,但我想我已经这样做了。
我怀疑(不知道哪个 let
语句导致了错误)您需要 return 从模式匹配中获取一些东西(即 | Log (message, ack) ->
之后的部分) ).
如果你不需要 return 任何东西,你可以只 return ()
最后,与两个外部 [=10= 的缩进级别相同]s,但注意模式匹配的所有分支都需要return相同的类型。
| Log (message, ack) ->
let CreateEventSourcingConnection() =
task {
let connection =
let ipEndPoint = IPEndPoint(IPAddress.Loopback, 1113)
EventStoreConnection.Create(ipEndlPoint)
do! connection.ConnectAsync()
return connection
}
let AddEventToStreamAsync (connection: IEventStoreConnection) streamName eventName message =
task {
let serializedEventData =
message
|> JsonConvert.SerializeObject
|> Encoding.UTF8.GetBytes
let event = EventData(Guid.NewGuid(), eventName, true, serializedEventData, null)
let! _ = connection.AppendToStreamAsync(streamName, int64 ExpectedVersion.Any, event)
()
}
错误:
The block following this 'let' is unfinished. Every code block is an expression and must have a result. 'let' cannot be the final code element in a block. Consider giving this block an explicit result.
我试过在定义它们之后调用这些函数。我也检查了我的缩进,我想应该没问题。我知道我需要 return 函数的值,但我想我已经这样做了。
我怀疑(不知道哪个 let
语句导致了错误)您需要 return 从模式匹配中获取一些东西(即 | Log (message, ack) ->
之后的部分) ).
如果你不需要 return 任何东西,你可以只 return ()
最后,与两个外部 [=10= 的缩进级别相同]s,但注意模式匹配的所有分支都需要return相同的类型。