private void CreateStream(bool withPull) { void Handler(Either <TSource, Exception> either) { if (either.IsLeft) { _open = true; _resource.SetResult(either.ToLeft().Value); if (withPull) { OnPull(); } } else { FailStage(either.ToRight().Value); } } var cb = GetAsyncCallback <Either <TSource, Exception> >(Handler); try { void Continue(Task <TSource> t) { if (t.IsCanceled || t.IsFaulted) { cb(new Right <TSource, Exception>(t.Exception)); } else { cb(new Left <TSource, Exception>(t.Result)); } } _source._create().ContinueWith(Continue); } catch (Exception ex) { FailStage(ex); } }
private void CreateStream(bool withPull) { var cb = GetAsyncCallback <Either <TSource, Exception> >(either => { if (either.IsLeft) { _resource.SetResult(either.ToLeft().Value); if (withPull) { OnPull(); } } else { FailStage(either.ToRight().Value); } }); try { _source._create().ContinueWith(t => { if (t.IsCompleted && !t.IsFaulted && t.Result != null) { cb(new Left <TSource, Exception>(t.Result)); } else { cb(new Right <TSource, Exception>(t.Exception)); } }); } catch (Exception ex) { FailStage(ex); } }
private void CreateResource() { _stage._create().OnComplete(resource => { try { CreatedCallback(resource); } catch (StreamDetachedException) { // stream stopped before created callback could be invoked, we need // to close the resource if it is was opened, to not leak it if (resource.IsSuccess) { _stage._close(resource.Success.Value); } else { // failed to open but stream is stopped already throw resource.Failure.Value; } } }); }