/// <summary> /// Connect this <see cref="Flow{TIn,TOut,TMat}"/> to a <see cref="Sink{TIn,TMat}"/>, concatenating the processing steps of both. /// The <paramref name="combine"/> function is used to compose the materialized values of this flow and that /// Sink into the materialized value of the resulting Sink. /// /// It is recommended to use the internally optimized <see cref="Keep.Left{TLeft,TRight}"/> and <see cref="Keep.Right{TLeft,TRight}"/> combiners /// where appropriate instead of manually writing functions that pass through one of the values. /// </summary> /// <typeparam name="TMat2">TBD</typeparam> /// <typeparam name="TMat3">TBD</typeparam> /// <param name="sink">TBD</param> /// <param name="combine">TBD</param> /// <returns>TBD</returns> public Sink <TIn, TMat3> ToMaterialized <TMat2, TMat3>(IGraph <SinkShape <TOut>, TMat2> sink, Func <TMat, TMat2, TMat3> combine) { if (IsIdentity) { return(Sink.FromGraph(sink as IGraph <SinkShape <TIn>, TMat2>) .MapMaterializedValue(mat2 => combine(default(TMat), mat2))); } var copy = sink.Module.CarbonCopy(); return(new Sink <TIn, TMat3>(Module .Fuse(copy, Shape.Outlet, copy.Shape.Inlets.First(), combine) .ReplaceShape(new SinkShape <TIn>(Shape.Inlet)))); }
/// <summary> /// Creates a Sink which when materialized will return an <see cref="Stream"/> which it is possible /// to read the values produced by the stream this Sink is attached to. /// /// This Sink is intended for inter-operation with legacy APIs since it is inherently blocking. /// /// You can configure the default dispatcher for this Source by changing the "akka.stream.blocking-io-dispatcher" or /// set it for a given Source by using <see cref="ActorAttributes.CreateDispatcher"/>. /// /// The <see cref="Stream"/> will be closed when the stream flowing into this <see cref="Sink{TIn,TMat}"/> completes, and /// closing the <see cref="Stream"/> will cancel this <see cref="Sink{TIn,TMat}"/>. /// </summary> /// <param name="readTimeout">The max time the read operation on the materialized stream should block</param> /// <returns>TBD</returns> public static Sink <ByteString, Stream> AsInputStream(TimeSpan?readTimeout = null) { readTimeout = readTimeout ?? TimeSpan.FromSeconds(5); return(Sink.FromGraph(new InputStreamSinkStage(readTimeout.Value))); }
/// <summary> /// Wrap the given <see cref="Sink"/> with a <see cref="Sink"/> that will restart it when it fails or complete using an exponential /// backoff. /// This <see cref="Sink"/> will never cancel, since cancellation by the wrapped <see cref="Sink"/> is always handled by restarting it. /// The wrapped <see cref="Sink"/> can however be completed by feeding a completion or error into this <see cref="Sink"/>. When that /// happens, the <see cref="Sink"/>, if currently running, will terminate and will not be restarted. This can be triggered /// simply by the upstream completing, or externally by introducing a <see cref="IKillSwitch"/> right before this <see cref="Sink"/> in the /// graph. /// The restart process is inherently lossy, since there is no coordination between cancelling and the sending of /// messages. When the wrapped <see cref="Sink"/> does cancel, this <see cref="Sink"/> will backpressure, however any elements already /// sent may have been lost. /// This uses the same exponential backoff algorithm as <see cref="Akka.Pattern.Backoff"/>. /// </summary> /// <param name="sinkFactory">A factory for producing the <see cref="Sink"/> to wrap.</param> /// <param name="minBackoff">Minimum (initial) duration until the child actor will started again, if it is terminated</param> /// <param name="maxBackoff">The exponential back-off is capped to this duration</param> /// <param name="randomFactor">After calculation of the exponential back-off an additional random delay based on this factor is added, e.g. `0.2` adds up to `20%` delay. In order to skip this additional delay pass in `0`.</param> /// <param name="maxRestarts">The amount of restarts is capped to this amount within a time frame of minBackoff. Passing `0` will cause no restarts and a negative number will not cap the amount of restarts.</param> public static Sink <T, NotUsed> WithBackoff <T, TMat>(Func <Sink <T, TMat> > sinkFactory, TimeSpan minBackoff, TimeSpan maxBackoff, double randomFactor, int maxRestarts) => Sink.FromGraph(new RestartWithBackoffSink <T, TMat>(sinkFactory, minBackoff, maxBackoff, randomFactor, maxRestarts));
/// <summary> /// Wrap the given <see cref="Sink"/> with a <see cref="Sink"/> that will restart it when it fails or complete using an exponential /// backoff. /// <para> /// This <see cref="Sink"/> will never cancel, since cancellation by the wrapped <see cref="Sink"/> is always handled by restarting it. /// The wrapped <see cref="Sink"/> can however be completed by feeding a completion or error into this <see cref="Sink"/>. When that /// happens, the <see cref="Sink"/>, if currently running, will terminate and will not be restarted. This can be triggered /// simply by the upstream completing, or externally by introducing a <see cref="IKillSwitch"/> right before this <see cref="Sink"/> in the /// graph. /// The restart process is inherently lossy, since there is no coordination between cancelling and the sending of /// messages. When the wrapped <see cref="Sink"/> does cancel, this <see cref="Sink"/> will backpressure, however any elements already /// sent may have been lost. /// </para> /// <para>This uses the same exponential backoff algorithm as <see cref="BackoffOptions"/>.</para> /// </summary> /// <param name="sinkFactory">A factory for producing the <see cref="Sink"/> to wrap.</param> /// <param name="settings"><see cref="RestartSettings" /> defining restart configuration</param> public static Sink <T, NotUsed> WithBackoff <T, TMat>(Func <Sink <T, TMat> > sinkFactory, RestartSettings settings) => Sink.FromGraph(new RestartWithBackoffSink <T, TMat>(sinkFactory, settings));
public static Sink <T, Task <ISourceRef <T> > > SourceRef <T>() => Sink.FromGraph <T, Task <ISourceRef <T> > >(new SinkRefStageImpl <T>(null));