| Log (message, ack) ->
let CreateEventSourcingConnection() =
task {
let connection =
let ipEndPoint = IPEndPoint(IPAddress.Loopback, 1113)
EventStoreConnection.Create(ipEndPoint)
do! connection.ConnectAsync()
return connection
}
let connectionM = CreateEventSourcingConnection ()
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)
()
}
AddEventToStreamAsync connectionM "a" "a"
该行
AddEventToStreamAsync connectionM "a" "a"
产生此错误
类型"任务"与类型"IEventStoreConnection"不兼容
我该如何解决这个问题?
您需要在从CreateEventSourcingConnection
返回的Task
上执行let!
,然后再将其传递给AddEventToStreamAsync
,一种方法是更改签名以执行任务,然后在其中let!
,如下所示:
let AddEventToStreamAsync (connectionTask: Task<IEventStoreConnection>) streamName eventName message =
task {
let serializedEventData =
message
|> JsonConvert.SerializeObject
|> Encoding.UTF8.GetBytes
let event = EventData(Guid.NewGuid(), eventName, true, serializedEventData, null)
let! connection = connectionTask
let! _ = connection.AppendToStreamAsync(streamName, int64 ExpectedVersion.Any, event)
()
}
AddEventToStreamAsync connectionM "a" "a"