private Task StartQueueWorker(IModel model, IActionStorage <IModel> storage,
                                      CancellationToken cancellation)
        {
            return(AsyncHelper.RunAsync(() =>
            {
                while (!cancellation.IsCancellationRequested)
                {
                    ActionItem <IModel> item;
                    try
                    {
                        item = storage.Wait(cancellation);
                    }
                    catch
                    {
                        break;
                    }

                    try
                    {
                        var result = item.Value(model);
                        item.TrySetResult(result);
                    }
                    catch (Exception ex)
                    {
                        item.TrySetException(ex);
                    }
                }
            }));
        }
 private async Task <T> RunConfiguration(IActionStorage <IModel> storage, CancellationToken cancellation)
 {
     try
     {
         return(await Task.Run(() =>
         {
             var invoker = new ActionInvoker <IModel>(storage, cancellation);
             var config = new LinkTopologyConfig(_logger, invoker);
             return _configureFunc(config);
         }, cancellation)
                .ConfigureAwait(false));
     }
     finally
     {
         storage.Dispose();
     }
 }
Beispiel #3
0
 public ActionInvoker(IActionStorage <TActor> storage) : this(storage, CancellationToken.None)
 {
 }
Beispiel #4
0
 public ActionInvoker(IActionStorage <TActor> storage, CancellationToken cancellation)
 {
     _storage      = storage ?? throw new ArgumentNullException(nameof(storage));
     _cancellation = cancellation;
 }