/// <summary> /// Initializes a context with the specified inner context and offset /// </summary> /// <param name="innerContext">The context which provides the base date and time</param> /// <param name="offset">The amount to shift the base date and time</param> public OffsetTimeContext(ITimeContext innerContext, TimeSpan offset) { Contract.Requires(innerContext != null); _innerContext = innerContext; _offset = offset; }
internal static Stream <R, T> NewStage(Stream <R, IterationIn <T> > input, ITimeContext <T> externalContext, int iterationNumber) { var stage = new Stage <EgressVertex <R, T>, T>(new TimeContext <T>(externalContext), Stage.OperatorType.IterationEgress, (i, v) => new EgressVertex <R, T>(i, v, iterationNumber), "FixedPoint.Egress"); stage.NewSurprisingTimeTypeInput(input, vertex => new ActionReceiver <R, IterationIn <T> >(vertex, m => vertex.OnReceive(m)), input.PartitionedBy); return(stage.NewOutput <R>(vertex => vertex.outputs, input.PartitionedBy)); }
/* Waits at most `timeout` and then completes it with the provided value. */ public static Future <A> timeout2 <A>( this Future <A> future, Duration timeout, Fn <A> onTimeout, ITimeContext tc = null ) { var timeoutF = delay(timeout, onTimeout, tc); return(new[] { future, timeoutF }.firstOf()); }
internal ReportingEgressStage(ITimeContext <T> externalContext) { receivers = new List <StageInput <string, IterationIn <T> > >(); intAggregator = null; doubleAggregator = null; this.stage = new Stage <ReportingEgressVertex <T>, T>(new TimeContext <T>(externalContext), Stage.OperatorType.IterationEgress, (i, v) => new ReportingEgressVertex <T>(i, v), "FixedPoint.ReportingEgress"); }
internal AggregateStatisticsStage(ITimeContext <T> context, string name) { this.stage = new Stage <AggregateStatisticsVertex <R, T>, T>(new TimeContext <T>(context), (i, v) => new AggregateStatisticsVertex <R, T>(i, v), name); Output = this.stage.NewOutputWithoutSealing(vertex => vertex.output, null); inputs = new List <StageInput <Pair <string, ReportingRecord <R> >, T> >(); }
public Gregorian(ITimeContext context, int year, Month month, int day, int hour = 0, int minute = 0, int second = 0, int milliseconds = 0, TimeZone timezone = null) { if (timezone == null) timezone = context.Gmt (); this.timezone = timezone; //TODO: Validate input this.time = new DateTime (year, (int)month, day, hour, minute, second, milliseconds, System.DateTimeKind.Utc).ToTime (context); }
internal static Stream <R, T> NewStage(Stream <R, IterationIn <T> > input, ITimeContext <T> externalContext, int iterationNumber) { var stage = new Stage <EgressShard <R, T>, T>(new OpaqueTimeContext <T>(externalContext), Stage.OperatorType.IterationEgress, (i, v) => new EgressShard <R, T>(i, v, iterationNumber), "FixedPoint.Egress"); stage.NewSurprisingTimeTypeInput(input, shard => new ActionReceiver <R, IterationIn <T> >(shard, m => shard.MessageReceived(m)), input.PartitionedBy); return(stage.NewOutput <R>(shard => shard.outputs, input.PartitionedBy)); }
internal static Stream <R, IterationIn <T> > NewStage(Stream <R, T> input, ITimeContext <IterationIn <T> > internalContext, Func <R, int> initialIteration) { var stage = new Stage <IngressVertex <R, T>, IterationIn <T> >(new TimeContext <IterationIn <T> >(internalContext), Stage.OperatorType.IterationIngress, (i, v) => new IngressVertex <R, T>(i, v, initialIteration), "FixedPoint.Ingress"); stage.NewSurprisingTimeTypeInput(input, vertex => new ActionReceiver <R, T>(vertex, m => vertex.MessageReceived(m)), input.PartitionedBy); return(stage.NewOutput(vertex => vertex.Output, input.PartitionedBy)); }
internal StageOutput <R, T> NewOutput <R, T>(ITimeContext <T> context, Expression <Func <R, int> > partitionedBy) where T : Time <T> { inputsSealed = true; var result = new StageOutput <R, T>(this, context, partitionedBy); return(result); }
public static Coroutine WithDelay( Duration duration, Action action, ITimeContext timeContext, MonoBehaviour behaviour = null ) { behaviour = behaviour ? behaviour : ASync.behaviour; var enumerator = WithDelayEnumerator(duration, action, timeContext); return(new UnityCoroutine(behaviour, enumerator)); }
internal Feedback(ITimeContext <IterationIn <TTime> > context, Expression <Func <TRecord, int> > partitionedBy, int maxIterations) { this.stage = new Stage <AdvanceVertex <TRecord, TTime>, IterationIn <TTime> >(new TimeContext <IterationIn <TTime> >(context), Stage.OperatorType.IterationAdvance, (i, v) => new AdvanceVertex <TRecord, TTime>(i, v, maxIterations), "Iterate.Advance"); this.input = this.stage.NewUnconnectedInput((message, vertex) => vertex.OnReceive(message), partitionedBy); this.output = this.stage.NewOutput(vertex => vertex.VertexOutput, partitionedBy); this.PartitionedBy = partitionedBy; this.MaxIterations = maxIterations; }
internal Feedback(ITimeContext <IterationIn <T> > context, Expression <Func <R, int> > partitionedBy, int maxIterations) { this.stage = new Stage <AdvanceShard <R, T>, IterationIn <T> >(new OpaqueTimeContext <IterationIn <T> >(context), Stage.OperatorType.IterationAdvance, (i, v) => new AdvanceShard <R, T>(i, v, maxIterations), "Iterate.Advance"); this.input = this.stage.NewUnconnectedInput((message, shard) => shard.MessageReceived(message), partitionedBy); this.output = this.stage.NewOutput(shard => shard.ShardOutput, partitionedBy); this.PartitionedBy = partitionedBy; this.MaxIterations = maxIterations; }
public static Tpl <Urls, Future <Either <ConfigFetchError, WWWWithHeaders> > > withTimeout( this Tpl <Urls, Future <Either <ConfigFetchError, WWWWithHeaders> > > tpl, Duration timeout, ITimeContext timeContext = default(ITimeContext) ) { timeContext = timeContext.orDefault(); return(tpl.map2((urls, future) => future .timeout(timeout, () => (ConfigFetchError) new ConfigTimeoutError(urls, timeout), timeContext) .map(e => e.flatten()) )); }
/* Waits at most `timeout` for the future to complete. Completes with * exception produced by `onTimeout` on timeout. */ public static Future <Either <B, A> > timeout <A, B>( this Future <A> future, Duration timeout, Fn <B> onTimeout, ITimeContext tc = null ) { var timeoutF = delay(timeout, () => future.value.fold( // onTimeout() might have side effects, so we only need to execute it if // there is no value in the original future once the timeout hits. () => onTimeout().left().r <A>(), v => v.right().l <B>() ), tc); return(new[] { future.map(v => v.right().l <B>()), timeoutF }.firstOf()); }
/// <summary> /// Constructs a new LoopContext from a containing TimeContext /// </summary> /// <param name="outerContext">outer time context</param> /// <param name="name">a descriptive name</param> public LoopContext(TimeContext <TTime> outerContext, string name) { externalContext = outerContext.Context; if (this.externalContext.HasReporting && this.externalContext.Manager.RootStatistics.HasInline) { internalContext = externalContext.Manager.MakeContextForScope <IterationIn <TTime> >( externalContext.Scope + "." + name, new ReportingEgressStage <TTime>(externalContext)); } else { internalContext = externalContext.Manager.MakeContextForScope <IterationIn <TTime> >( externalContext.Scope + "." + name, null); } }
/* action should return true if it wants to keep running. */ public static Coroutine every( this ITimeContext tc, Duration duration, Fn <bool> action, string name = null ) { var cr = new TimeContextEveryDurationCoroutine(); Action repeatingInvoke = null; repeatingInvoke = () => { var keepRunning = action(); if (keepRunning) { cr.current = tc.after(duration, repeatingInvoke, name); } else { cr.stop(); } }; cr.current = tc.after(duration, repeatingInvoke, name); return(cr); }
public static IEnumerator WithDelayEnumerator( Duration duration, Action action, ITimeContext timeContext ) { if (timeContext == TimeContext.playMode) { // WaitForSeconds is optimized Unity in native code // waiters that extend CustomYieldInstruction (eg. WaitForSecondsRealtime) call C# code every frame, // so we don't need special handling for them yield return(new WaitForSeconds(duration.seconds)); } else { var waiter = timeContext == TimeContext.fixedTime ? CoroutineUtils.waitFixed : null; var waitTime = timeContext.passedSinceStartup + duration; while (waitTime > timeContext.passedSinceStartup) { yield return(waiter); } } action(); }
internal TimeContext(ITimeContext <TTime> context) { this.Context = context; }
public static ITimeContext orDefault(this ITimeContext tc) => tc ?? DEFAULT;
public static Future <A> delay <A>(Duration duration, A value, ITimeContext tc = null) => a <A>(p => tc.orDefault().after(duration, () => p.complete(value)));
/* Waits at most `timeout` for the future to complete. */ public static Future <Either <Duration, A> > timeout <A>( this Future <A> future, Duration timeout, ITimeContext tc = null ) => future.timeout(timeout, () => timeout, tc);
internal OpaqueTimeContext(ITimeContext <T> context) { this.Context = context; }
public static Coroutine every( this ITimeContext tc, Duration duration, Action action, string name = null ) => tc.every(duration, () => { action(); return(true); }, name);
internal TimeContextManager(InternalComputation g) { this.internalComputation = g; this.rootContext = null; this.reporting = null; }
internal void InitializeReporting(bool makeDomain, bool makeInline, bool doAggregate) { this.reporting = new Reporting.RootReporting(this, makeDomain, makeInline, doAggregate); this.rootContext = MakeContextForScope <Epoch>("Root", this.reporting); }
internal TimeContextManager(Runtime.InternalGraphManager g) { this.graphManager = g; this.rootContext = null; this.reporting = null; }
public TimeContextTimer(TickableTimeContext tickableTimeContext) : base(() => tickableTimeContext.Time) { TimeContext = tickableTimeContext; }
internal RootStatisticsStage(ITimeContext <Epoch> context, string name, string outputFile) { this.stage = new Stage <RootStatisticsVertex, Epoch>(new Placement.SingleVertex(0, 0), new TimeContext <Epoch>(context), Stage.OperatorType.Default, (i, v) => new RootStatisticsVertex(i, v, outputFile), name); receivers = new List <StageInput <string, Epoch> >(); }
public UnixEpoch(decimal seconds,ITimeContext context) : this(new Time(seconds,context),null) { }
public CoroutineInterval(Duration duration, ITimeContext timeContext) { this.timeContext = timeContext; startTime = timeContext.passedSinceStartup; endTime = startTime + duration; }
public static Time ToTime(this DateTime dateTime, ITimeContext context) { return new Time(new decimal((dateTime.ToUniversalTime() - DateTimeEpoch()).TotalSeconds), context); }
internal static Stream <R, IterationIn <T> > NewStage(Stream <R, T> input, ITimeContext <IterationIn <T> > internalContext) { return(NewStage(input, internalContext, null)); }
// creates a new send socket for the stage to send records into. internal StageOutput <R, T> NewOutput <R, T>(ITimeContext <T> context) where T : Time <T> { return(this.NewOutput <R, T>(context, null)); }
public static Future <A> delayFrames <A>(int framesToSkip, A value, ITimeContext tc = null) => a <A>(p => tc.orDefault().afterXFrames(framesToSkip, () => p.complete(value)));