public Awaiter(IScope scope, Action onBreakInner) { _scope = scope; if (_scope.Disposed) { _unsub = Empty.Action(); return; } _break = onBreakInner; _scope.Subscribe(OnDispose); _unsub = Unsubscribe; void Unsubscribe() { if (!_scope.Disposing) { _scope.Unsubscribe(OnDispose); } } void OnDispose() { if (_continuation != null) { InvokeAndFree(ref _continuation); } } }
static void InvokeAndFree(ref Action action) { var tmp = action; action = Empty.Action(); tmp.Invoke(); }
public static Awaiter GetAwaiter(this IScope outer) { return(new Awaiter(outer, Empty.Action())); }