コード例 #1
0
        public void OnNextFlush(AsyncFlushHandler handler)
        {
            var myAction = new MyAction(handler);

            if (Interlocked.CompareExchange(ref flushAction, myAction, null) != null)
            {
                throw new InvalidOperationException();
            }
        }
コード例 #2
0
        async Task FlushAsync(string message, AsyncFlushFunc func, AsyncFlushHandler handler, CancellationToken cancellationToken)
        {
            LogDebug(message);
            try {
                await handler(func, cancellationToken).ConfigureAwait(false);

                LogDebug($"{message} done");
            } catch (Exception ex) {
                if (IgnoreErrors)
                {
                    return;
                }
                LogDebug($"{message} failed: {ex}");
                throw;
            }
        }
コード例 #3
0
        public override Task FlushAsync(CancellationToken cancellationToken)
        {
            var message = $"{Name}.FlushAsync()";

            AsyncFlushFunc    asyncBaseFlush    = base.FlushAsync;
            AsyncFlushHandler asyncFlushHandler = (func, ct) => func(ct);

            var action = Interlocked.Exchange(ref flushAction, null);

            if (action?.AsyncFlush != null)
            {
                message += " - action";
                return(FlushAsync(message, asyncBaseFlush, action.AsyncFlush, cancellationToken));
            }

            return(FlushAsync(message, asyncBaseFlush, asyncFlushHandler, cancellationToken));
        }
コード例 #4
0
 public MyAction(AsyncFlushHandler handler)
 {
     AsyncFlush = handler;
 }