public ServiceBuilder(IServiceSchema schema, ServiceLink link) { Schema = schema; Link = link; }
public async Task <T> WaitFor <T>(string correlationId, CancellationToken token, IServiceSchema schema) { var taskSource = new TaskCompletionSource <ILinkConsumedMessage <byte[]> >(); GuardDispose(() => _subscribers.TryAdd(correlationId, taskSource)); try { token.Register(() => taskSource.TrySetCanceled(token)); var msg = await taskSource.Task; var obj = _link.PayloadManager.Deserialize <T>(msg, schema.Types); switch (obj) { case Exception ex: throw ex; case RpcFail fail: throw new RpcFailException(fail.Message, fail.Kind); case T t: return(t); } throw new InvalidCastException($"Invalid message received {obj?.GetType()}"); } finally { _subscribers.TryRemove(correlationId, out var _); } }