/// <summary> /// Projects the result of the task into a new form. /// </summary> public static IAwaitable <TResult> Select <TResult>(this IAwaitable input, Func <TResult> f) { var result = new Awaitable <TResult>(); input.Subscribe(() => result.Emit(f())); return(result); }
/// <summary> /// Creates a task that completes (or cancels) when either the input task completes or the cancellation token is signalled. /// On cancellation, the original task still runs to completion because there is no way to preemptively cancel it. /// </summary> public static IAwaitable WithCancellation(this IAwaitable input, CancellationToken ct) { var result = new Awaitable(ct); input.Subscribe(() => result.Emit()); return(result); }
/// <summary> /// Creates a task that completes (or cancels) when either the input task completes or the cancellation token is signalled. /// On cancellation, the original task still runs to completion because there is no way to preemptively cancel it. /// </summary> public static IAwaitable <T> WithCancellation <T>(this IAwaitable <T> input, CancellationToken ct) { var result = new Awaitable <T>(ct); input.Subscribe(v => result.Emit(v)); return(result); }
/// <summary> /// Creates a continuation that executes when the target task completes. /// </summary> public static IAwaitable <TResult> ContinueWith <TResult>(this IAwaitable awaitable, Func <TResult> fun) { var result = new Awaitable <TResult>(); awaitable.Subscribe(() => { result.Emit(fun()); }); return(result); }
/// <summary> /// Creates a continuation that executes when the target task completes. /// </summary> public static IAwaitable ContinueWith <TResult>(this IAwaitable awaitable, Action fun) { var result = new Awaitable(); awaitable.Subscribe(() => { fun(); result.Emit(); }); return(result); }
/// <summary> /// Creates a continuation that executes when the target task completes. /// </summary> public static IAwaitable ContinueWith <T>(this IAwaitable <T> awaitable, Action <T> action) { var result = new Awaitable(); awaitable.Subscribe(v => { action(v); result.Emit(); }); return(result); }