public void Send <T>(INCollatedMessage <T> message, Action <T> callback, Action <INError> errback) { // Set a collation ID to dispatch callbacks on receive string collationId = Guid.NewGuid().ToString(); message.SetCollationId(collationId); // Track callbacks for message var pair = new KeyValuePair <Action <object>, Action <INError> >((data) => { callback((T)data); }, errback); collationIds.Add(collationId, pair); var stream = new MemoryStream(); message.Payload.WriteTo(stream); Logger.TraceFormatIf(Trace, "SocketWrite: {0}", message.Payload); transport.SendAsync(stream.ToArray(), true, (bool completed) => { if (!completed) { // The write may have failed; don't track it collationIds.Remove(collationId); } }); }
public void Send <T>(INCollatedMessage <T> message, Action <T> callback, Action <INError> errback) { _client.Send <T>(message, (T result) => { Enqueue(() => callback(result)); }, (INError error) => { Enqueue(() => errback(error)); }); }