public static CommandQuery FromEvent <TEvent>(this CommandQueryBuilder builder, Task <TEvent> currentValue, Func <TEvent?, bool> check) where TEvent : class { var context = ExposedReceiveActor.ExposedContext; return(builder.FromExternal(check, action => { currentValue.ContinueWith(t => { if (t.IsCompleted) { action(t.Result); } }); context.ActorOf(dsl => { dsl.OnPreStart += actorContext => actorContext.System.EventStream.Subscribe <TEvent>(actorContext.Self); dsl.OnPostStop += actorContext => actorContext.System.EventStream.Unsubscribe(actorContext.Self); dsl.Receive <TEvent>((e, c) => action(e)); }); })); }
public static CommandQuery FromEventSource <TData>(this CommandQueryBuilder builder, IEventSource <TData> source, Func <TData, bool> check) where TData : class => builder.FromExternal <TData>(d => d != null && check(d), action => source.RespondOn(ActorCell.GetCurrentSelfOrNoSender() ?? ActorRefs.Nobody, action));
public static CommandQuery FromEventSource <TData>(this CommandQueryBuilder builder, IEventSource <TData> source, Func <TData, bool> check, TData defaultValue) => builder.FromExternal(check, action => source.RespondOn(ActorCell.GetCurrentSelfOrNoSender() ?? ActorRefs.Nobody, action), defaultValue);