Exemple #1
0
 public StatefulSynchronizationContextInvokeArgs(IStatefulSynchronizationContext <TCtxState> syncCtx, TCtxState syncCtxState, TState state, CancellationToken ct)
 {
     SyncCtx      = syncCtx;
     SyncCtxState = syncCtxState;
     State        = state;
     Ct           = ct;
 }
Exemple #2
0
 public static void InvokeOneWay <TCtxState>(this IStatefulSynchronizationContext <TCtxState> syncCtx, Action <StatefulSynchronizationContextInvokeArgs <TCtxState, Nil> > action, IContext ctx = default)
 {
     syncCtx.EnsureNotNull(nameof(syncCtx));
     action.EnsureNotNull(nameof(action));
     //
     syncCtx.ExecuteOneWay(action: execute, state: Nil.Value, ct: ctx.Ct());
     //
     void execute(IStatefulSynchronizationContext <TCtxState> locSyncCtx, IVh <TCtxState> locSyncCtxState, Nil locState, CancellationToken locCt)
     => action(obj: new StatefulSynchronizationContextInvokeArgs <TCtxState, Nil>(syncCtx: locSyncCtx, syncCtxState: locSyncCtxState.Value, state: locState, ct: locCt));
 }
Exemple #3
0
        public static async Task <TResult> InvokeAsync <TCtxState, TResult>(this IStatefulSynchronizationContext <TCtxState> syncCtx, Func <StatefulSynchronizationContextInvokeArgs <TCtxState, Nil>, TResult> func, CancellationToken ct = default)
        {
            syncCtx.EnsureNotNull(nameof(syncCtx));
            func.EnsureNotNull(nameof(func));
            //
            return(await syncCtx.ExecuteAsync(func : execute, state : Nil.Value, ct : ct).ConfigureAwait(false));

            //
            TResult execute(IStatefulSynchronizationContext <TCtxState> locSyncCtx, IVh <TCtxState> locSyncCtxState, Nil locState, CancellationToken locCt)
            => func(arg: new StatefulSynchronizationContextInvokeArgs <TCtxState, Nil>(syncCtx: locSyncCtx, syncCtxState: locSyncCtxState.Value, state: Nil.Value, ct: locCt));
        }
Exemple #4
0
        public static async Task InvokeAsync <TCtxState, TState>(this IStatefulSynchronizationContext <TCtxState> syncCtx, Action <StatefulSynchronizationContextInvokeArgs <TCtxState, TState> > action, TState state, CancellationToken ct = default)
        {
            syncCtx.EnsureNotNull(nameof(syncCtx));
            action.EnsureNotNull(nameof(action));
            //
            await syncCtx.ExecuteAsync(func : execute, state : state, ct : ct).ConfigureAwait(false);

            //
            Nil execute(IStatefulSynchronizationContext <TCtxState> locSyncCtx, IVh <TCtxState> locSyncCtxState, TState locState, CancellationToken locCt)
            {
                action(obj: new StatefulSynchronizationContextInvokeArgs <TCtxState, TState>(syncCtx: locSyncCtx, syncCtxState: locSyncCtxState.Value, state: locState, ct: locCt));
                return(Nil.Value);
            }
        }