/// <summary> /// TBD /// </summary> /// <param name="context">TBD</param> /// <param name="task">TBD</param> /// <returns>TBD</returns> public override IPublisher <ByteString> Create(MaterializationContext context, out Task <IOResult> task) { var materializer = ActorMaterializerHelper.Downcast(context.Materializer); var ioResultPromise = new TaskCompletionSource <IOResult>(); IPublisher <ByteString> pub; try { // can throw, i.e. FileNotFound var inputStream = _createInputStream(); var props = InputStreamPublisher .Props(inputStream, ioResultPromise, _chunkSize) .WithDispatcher(context .EffectiveAttributes .GetMandatoryAttribute <ActorAttributes.Dispatcher>() .Name); var actorRef = materializer.ActorOf(context, props); pub = new ActorPublisherImpl <ByteString>(actorRef); } catch (Exception ex) { ioResultPromise.TrySetException(ex); pub = new ErrorPublisher <ByteString>(ex, Attributes.GetNameOrDefault("inputStreamSource")); } task = ioResultPromise.Task; return(pub); }
public void ActorPublisher_should_handle_stash() { var probe = CreateTestProbe(); var actorRef = Sys.ActorOf(TestPublisherWithStash.Props(probe.Ref)); var p = new ActorPublisherImpl <string>(actorRef); var s = this.CreateSubscriberProbe <string>(); p.Subscribe(s); s.Request(2); s.Request(3); actorRef.Tell("unstash"); probe.ExpectMsg(new TotalDemand(5)); probe.ExpectMsg(new TotalDemand(5)); s.Request(4); probe.ExpectMsg(new TotalDemand(9)); s.Cancel(); }