public override void OnPull() { var source = _stage._sourceFactory(); var subSink = new SubSinkInlet <TOut>(this, "LazySource"); subSink.Pull(); SetHandler(_stage.Out, () => subSink.Pull(), () => { subSink.Cancel(); CompleteStage(); }); subSink.SetHandler(new LambdaInHandler(() => Push(_stage.Out, subSink.Grab()))); try { var value = SubFusingMaterializer.Materialize(source.ToMaterialized(subSink.Sink, Keep.Left), _inheritedAttributes); _completion.SetResult(value); } catch (Exception e) { subSink.Cancel(); FailStage(e); _completion.TrySetException(e); } }
protected SubSinkInlet <TOut> CreateSubInlet(Outlet <TOut> outlet) { var sinkIn = new SubSinkInlet <TOut>(this, $"RestartWithBackoff{_name}.subIn"); sinkIn.SetHandler(new LambdaInHandler( onPush: () => Push(Out, sinkIn.Grab()), onUpstreamFinish: () => { if (_finishing || MaxRestartsReached() || _onlyOnFailures) { Complete(Out); } else { ScheduleRestartTimer(); } }, /* * upstream in this context is the wrapped stage */ onUpstreamFailure: ex => { if (_finishing || MaxRestartsReached()) { Fail(Out, ex); } else { Log.Warning(ex, "Restarting graph due to failure."); ScheduleRestartTimer(); } })); SetHandler(Out, onPull: () => sinkIn.Pull(), onDownstreamFinish: () => { _finishing = true; sinkIn.Cancel(); }); return(sinkIn); }
protected SubSinkInlet <T> CreateSubInlet <T>(Outlet <T> outlet) { var sinkIn = new SubSinkInlet <T>(this, $"RestartWithBackoff{_name}.subIn"); sinkIn.SetHandler(new LambdaInHandler( onPush: () => { Push(Out, sinkIn.Grab()); }, onUpstreamFinish: () => { if (_finishing) { Complete(Out); } else { Log.Debug("Graph out finished"); OnCompleteOrFailure(); } }, onUpstreamFailure: ex => { if (_finishing) { Fail(_shape.Outlets.First(), ex); } else { Log.Error(ex, "Restarting graph due to failure"); OnCompleteOrFailure(); } })); SetHandler(Out, onPull: () => sinkIn.Pull(), onDownstreamFinish: () => { _finishing = true; sinkIn.Cancel(); }); return(sinkIn); }
public override void OnPush() => Push(_stage.Outlet, _sinkIn.Grab());