示例#1
0
 /// <summary>
 /// Shortcut for running this <see cref="Source{TOut,TMat}"/> with a reduce function.
 /// The given function is invoked for every received element, giving it its previous
 /// output (from the second element) and the element as input.
 /// The returned <see cref="Task{TOut}"/> will be completed with value of the final
 /// function evaluation when the input stream ends, or completed with Failure
 /// if there is a failure signaled in the stream.
 /// </summary>
 /// <param name="reduce">TBD</param>
 /// <param name="materializer">TBD</param>
 /// <returns>TBD</returns>
 public Task <TOut> RunSum(Func <TOut, TOut, TOut> reduce, IMaterializer materializer)
 => RunWith(Sink.Sum(reduce), materializer);
示例#2
0
 /// <summary>
 /// Shortcut for running this <see cref="Source{TOut,TMat}"/> with a foreach procedure. The given procedure is invoked
 /// for each received element.
 /// The returned <see cref="Task"/> will be completed with Success when reaching the
 /// normal end of the stream, or completed with Failure if there is a failure signaled in
 /// the stream.
 /// </summary>
 /// <param name="action">TBD</param>
 /// <param name="materializer">TBD</param>
 /// <returns>TBD</returns>
 public Task RunForeach(Action <TOut> action, IMaterializer materializer)
 => RunWith(Sink.ForEach(action), materializer);
示例#3
0
        /// <summary>
        ///  Materializes this Source immediately.
        /// </summary>
        /// <param name="materializer">The materializer.</param>
        /// <returns>A tuple containing the (1) materialized value and (2) a new <see cref="Source"/>
        ///  that can be used to consume elements from the newly materialized <see cref="Source"/>.</returns>
        public Tuple <TMat, Source <TOut, NotUsed> > PreMaterialize(IMaterializer materializer)
        {
            var tup = ToMaterialized(Sink.AsPublisher <TOut>(fanout: true), Keep.Both).Run(materializer);

            return(Tuple.Create(tup.Item1, Source.FromPublisher(tup.Item2)));
        }
示例#4
0
 /// <summary>
 /// Shortcut for running this <see cref="Source{TOut,TMat}"/> with a async <paramref name="aggregate"/> function.
 /// The given function is invoked for every received element, giving it its previous
 /// output (or the given <paramref name="zero"/> value) and the element as input.
 /// The returned <see cref="Task{TOut2}"/> will be completed with value of the final
 /// function evaluation when the input stream ends, or completed with Failure
 /// if there is a failure signaled in the stream.
 /// </summary>
 /// <typeparam name="TOut2">TBD</typeparam>
 /// <param name="zero">TBD</param>
 /// <param name="aggregate">TBD</param>
 /// <param name="materializer">TBD</param>
 /// <returns>TBD</returns>
 public Task <TOut2> RunAggregateAsync <TOut2>(TOut2 zero, Func <TOut2, TOut, Task <TOut2> > aggregate, IMaterializer materializer)
 => RunWith(Sink.AggregateAsync(zero, aggregate), materializer);
示例#5
0
 /// <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>
 public static Sink <T, NotUsed> WithBackoff <T, TMat>(Func <Sink <T, TMat> > sinkFactory, TimeSpan minBackoff, TimeSpan maxBackoff, double randomFactor)
 => Sink.FromGraph(new RestartWithBackoffSink <T, TMat>(sinkFactory, minBackoff, maxBackoff, randomFactor));
示例#6
0
 /// <summary>
 /// Converts this Flow to a <see cref="IRunnableGraph{TMat}"/> that materializes to a Reactive Streams <see cref="IProcessor{T1,T2}"/>
 /// which implements the operations encapsulated by this Flow. Every materialization results in a new Processor
 /// instance, i.e. the returned <see cref="IRunnableGraph{TMat}"/> is reusable.
 /// </summary>
 /// <returns>A <see cref="IRunnableGraph{TMat}"/> that materializes to a <see cref="IProcessor{T1,T2}"/> when Run() is called on it.</returns>
 public IRunnableGraph <IProcessor <TIn, TOut> > ToProcessor()
 => Source.AsSubscriber <TIn>()
 .Via(this)
 .ToMaterialized(Sink.AsPublisher <TOut>(false), Keep.Both)
 .MapMaterializedValue(t => new FlowProcessor <TIn, TOut>(t.Item1, t.Item2) as IProcessor <TIn, TOut>);
示例#7
0
 //private readonly IRunnableGraph<(UniqueKillSwitch, ISinkQueue<T>)> _graph;
 public StreamsAsyncEnumerableRerunnable(Source <T, TMat> source, IMaterializer materializer)
 {
     _source       = source;
     _materializer = materializer;
     thisSinkQueue = defaultSinkqueue;
 }
示例#8
0
 /// <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)));
 }
示例#9
0
 public static Sink <T, Task <ISourceRef <T> > > SourceRef <T>() =>
 Sink.FromGraph <T, Task <ISourceRef <T> > >(new SinkRefStageImpl <T>(null));