Beispiel #1
0
 public ServiceBuilder(IServiceSchema schema, ServiceLink link)
 {
     Schema = schema;
     Link   = link;
 }
Beispiel #2
0
        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 _);
            }
        }