public static bool CheckCancelled(LocalEvent <Cancellable> evt) { var cancellable = new Cancellable(); evt.Fire(cancellable); return(cancellable.IsCancelled); }
public void SetRelative(Vector2 baseLoc, Vector2 axis, int thisIndex, int selectedIndex, int total, bool setImmediate, bool locked = false) { int center = total / 2; var selLoc = axis * ((selectedIndex - center) * 0.8f); var dist = Mathf.Abs(thisIndex - selectedIndex); var effectiveDist = Mathf.Sign(thisIndex - selectedIndex) * Mathf.Pow(dist, 0.6f); var myLoc = baseLoc + selLoc + axis * (effectiveDist * 4.2f); var isSel = thisIndex == selectedIndex; var scale = isSel ? selectedScale : unselectedScale; var alpha = isSel ? 1 : 0.7f; var color = (locked ? Color.gray : Color.white).WithA(alpha); canceller?.Cancel(); canceller = new Cancellable(); float time = 0.4f; if (setImmediate) { tr.localPosition = myLoc; tr.localScale = new Vector3(scale, scale, scale); sr.color = color; } else { RunDroppableRIEnumerator(tr.GoTo(myLoc, time, M.EOutSine, canceller)); RunDroppableRIEnumerator(tr.ScaleTo(scale, time, M.EOutSine, canceller)); RunDroppableRIEnumerator(sr.ColorTo(color, time, M.EOutSine, canceller)); } }
public static void EjectWithOperation(this GLib.Mount m, MountUnmountFlags flags, GLib.MountOperation operation, Cancellable cancellable, AsyncReadyCallback callback) { m.MaybeEmptyTrashWithAction(() => { NativeInterop.EjectWithOperation(m, flags, operation, cancellable, callback); }); }
public void ScheduleCancel() { var system = ActorSystem.Create("SchedulerTests"); AutoResetEvent[] firedEvents = new AutoResetEvent[3]; firedEvents[0] = new AutoResetEvent(false); firedEvents[1] = new AutoResetEvent(false); firedEvents[2] = new AutoResetEvent(false); var actor = system.ActorOf(typeof(SchedulerTestRepeating), Props.With((object)firedEvents)); Cancellable schedule = system.Scheduler.Schedule(100, 100, actor, "FIRED"); var fired1 = firedEvents[0].WaitOne(1000, false); var fired2 = firedEvents[1].WaitOne(1000, false); schedule.Cancel(); var fired3 = firedEvents[2].WaitOne(1000, false); system.Stop(actor); system.Shutdown(); Assert.IsTrue(fired1); Assert.IsTrue(fired2); Assert.IsFalse(fired3); Assert.IsTrue(schedule.Cancelled); }
public void AttemptToStartMode() { if (StartingModeDelay) { return; } if (Cancellable.CheckCancelled(OnCheckIfModeCanStartEvent)) { StartingModeTime = Network.time; return; } if (StartingModeTime == -1.0 || Network.time - StartingModeTime < StartingModeTimeout) { foreach (var player in ValidPlayers) { if (!player.Stuck && !player.HasLoadedLevel(true)) { return; } } } StartingModeDelay = true; // StartModeAfterDelay is a fix for the mode sometimes starting so early that the loading screen won't disappear DistanceServerMainStarter.Instance.StartCoroutine(StartModeAfterDelay(5.0f)); }
public ValueProcessorItem GetProcessor(ValueProcessorItem valueItem, CancellationToken?token = null) { if (valueItem.IsValid("sql") == false) { return(valueItem); } valueItem.Value ??= valueItem.Item.RawValue; if (string.IsNullOrWhiteSpace(valueItem.Item.Attributes?["connection_string"])) { throw new MissingFieldException( $"Missing 'connection_string' attribute for tag '{valueItem.Item.FullName}"); } try { DbContext db = GetDbContext(valueItem.Item.Attributes?["connection_string"]); valueItem.Data = token == null? db.ExecuteQuery(valueItem.Value, null) : Cancellable.CancellableRun <IEnumerable <dynamic> >( () => db.ExecuteQuery(valueItem.Value, null), (CancellationToken)token); return(valueItem); } catch (Exception ex) { throw new FormatException($"SQL Error executing query for tag {valueItem.Item.FullName}:\r\n" + $"SQL query:\r\n{valueItem.Value}\r\n\r\n" + $"Error msg: \r\n{ex.Message}"); } }
void AttemptToAdvanceLevel() { if (Server.StartingLevel || !Server.HasModeStarted) { Log.Debug($"Mode not started, not advancing normally."); return; } if (Server.ValidPlayers.Count == 0) { Log.Debug($"No players, not advancing normally."); return; } if (ServerStage != Stage.Started) { return; } if (Cancellable.CheckCancelled(OnCheckIfLevelCanAdvanceEvent)) { return; } Log.Debug("Advancing level from AttemptToAdvanceLevel"); AdvanceLevel(); }
private void CancelExecution() { if (this.cancellable != null) { this.cancellable.Cancel(); this.cancellable = null; } }
protected virtual Task OnErrorAsync(HTaskSchedularErrorEventArgs e) { if (e == null) { return(Task.CompletedTask); } return(Cancellable.CancellableRunAsync( () => Error?.Invoke(e.Sender, e) , this.Cts.Token)); }
public static void EjectWithOperation(Mount mount, MountUnmountFlags flags, MountOperation op, Cancellable cancellable, AsyncReadyCallback cb) { NativeHelper(() => { GLibSharp.AsyncReadyCallbackWrapper cb_wrapper = new GLibSharp.AsyncReadyCallbackWrapper(cb); g_mount_eject_with_operation(mount.Handle, (int)flags, op == null ? IntPtr.Zero : op.Handle, cancellable == null ? IntPtr.Zero : cancellable.Handle, cb_wrapper.NativeDelegate, IntPtr.Zero); }, GIO_NOT_FOUND, "Failed to eject with operation name: {0}"); }
/// <since>4.2</since> public virtual void Completed() { this.abortLock.Lock(); try { this.cancellable = null; } finally { this.abortLock.Unlock(); } }
public static void TestCancellation() { CoroutineRegularUpdater cru = new GameObject().AddComponent <CoroutineRegularUpdater>(); var cts = new Cancellable(); cru.RunRIEnumerator(LeaveOnCancel(cts)); cru.RegularUpdate(); cru.RegularUpdate(); Assert.AreEqual(cru.NumRunningCoroutines, 1); cts.Cancel(); cru.RegularUpdate(); Assert.AreEqual(cru.NumRunningCoroutines, 0); }
/// <summary> /// Start monitoring scheduled tasks in order to trigger IsTaskDue event when tasks are ready for execution. /// </summary> /// <param name="cancellationToken">If provided, the monitoring force stops all running tasks</param> /// <returns>a running monitoring task</returns> public Task Start(CancellationToken?cancellationToken = null) { if (!this.RunSwitch.TryOpen()) { return(Task.CompletedTask); } //this.Load(); this.Cts = cancellationToken == null ? new CancellationTokenSource() : CancellationTokenSource.CreateLinkedTokenSource( (CancellationToken)cancellationToken); return(Cancellable.CancellableRunAsync(MonitorTasks, this.Cts.Token)); }
public void TestCancel() { var v = new Vector2(-2, -2); var cors = new Coroutines(); var ct = new Cancellable(); var tw = (Tween.TweenTo(Vector2.Zero, Vector2.One, 20, x => v = x, Easers.ELinear, ct)).Run(cors); cors.Step(); cors.Step(); VecEq(v, Vector2.One / 20f); ct.Cancel(1); cors.Step(); VecEq(v, Vector2.One); Assert.AreEqual(tw.Result, Completion.SoftSkip); ct = new Cancellable(); tw = (Tween.TweenTo(Vector2.Zero, Vector2.One, 20, x => v = x, Easers.ELinear, ct)).Run(cors); cors.Step(); cors.Step(); VecEq(v, Vector2.One / 20f); ct.Cancel(2); cors.Step(); VecEq(v, Vector2.One / 20f); Assert.IsTrue(tw.IsCanceled); ct = new Cancellable(); var t0 = (Tween.TweenTo(Vector2.Zero, Vector2.One, 5, x => v = x, Easers.ELinear, ct)); tw = t0.Then(t0.Reverse()).Run(cors); cors.Step(); cors.Step(); VecEq(v, new Vector2(0.2f, 0.2f)); ct.Cancel(1); cors.Step(); VecEq(v, Vector2.Zero); Assert.AreEqual(tw.Result, Completion.SoftSkip); ct = new Cancellable(); t0 = (Tween.TweenTo(Vector2.Zero, Vector2.One, 5, x => v = x, Easers.ELinear, ct)); tw = t0.Then(t0.Reverse()).Run(cors); cors.Step(); cors.Step(); VecEq(v, new Vector2(0.2f, 0.2f)); ct.Cancel(2); cors.Step(); VecEq(v, new Vector2(0.2f, 0.2f)); Assert.IsTrue(tw.IsCanceled); }
/// <summary> /// Outer waiter-- Will not cancel if cancelled /// </summary> public static void WaitThenCancel(CoroutineRegularUpdater Exec, ICancellee cT, float time, bool zeroToInfinity, Cancellable toCancel) { cT.ThrowIfCancelled(); if (zeroToInfinity && time < float.Epsilon) { time = float.MaxValue; } Exec.RunRIEnumerator(WaitFor(time, cT, () => { if (!cT.Cancelled) { toCancel.Cancel(); } })); }
public virtual void SetReleaseTrigger(ConnectionReleaseTrigger releaseTrigger) { if (this.aborted) { return; } this.abortLock.Lock(); try { this.cancellable = new _Cancellable_80(releaseTrigger); } finally { this.abortLock.Unlock(); } }
/// <since>4.2</since> public virtual void SetCancellable(Cancellable cancellable) { if (this.aborted) { return; } this.abortLock.Lock(); try { this.cancellable = cancellable; } finally { this.abortLock.Unlock(); } }
public virtual void SetConnectionRequest(ClientConnectionRequest connRequest) { if (this.aborted) { return; } this.abortLock.Lock(); try { this.cancellable = new _Cancellable_60(connRequest); } finally { this.abortLock.Unlock(); } }
private void MonitorTasks() { while (!this.Cts.IsCancellationRequested) { foreach (var task in this.Tasks) { Cancellable.CancellableRunAsync(() => { this.ThreadTraffic.QueueCall(() => { Process(task); }, 0, task.UniqueKey); }, this.Cts.Token); } Task.Delay(this.TickInterval, this.Cts.Token).GetAwaiter().GetResult(); } }
/// <summary> /// Note that this may call DONE earlier than TIME if it is cancelled by another SHAKE call. /// </summary> public void Shake(float time, FXY?magnitude, float magMul, ICancellee?cT, Action?done) { foreach (var cts in cancelTokens) { cts.Cancel(); } cancelTokens.Clear(); magnitude ??= (t => M.Sin(M.PI * (0.4f + 0.6f * t / time))); var x = new Cancellable(); cancelTokens.Add(x); var joint = new JointCancellee(x, cT); RunDroppableRIEnumerator(IShake(time, magnitude, magMul, joint, () => { cancelTokens.Remove(x); done?.Invoke(); })); }
public static IEnumerator TestAutoCancellation() { CoroutineRegularUpdater cru = new GameObject().AddComponent <CoroutineRegularUpdater>(); var cts = new Cancellable(); cru.RunRIEnumerator(NestLoC(cts)); cts.Cancel(); cru.gameObject.SetActive(false); Assert.AreEqual(cru.NumRunningCoroutines, 0); cru.gameObject.SetActive(true); cru.RunDroppableRIEnumerator(NestLoC(Cancellable.Null)); cru.gameObject.SetActive(false); Assert.AreEqual(cru.NumRunningCoroutines, 0); cru.gameObject.SetActive(true); cru.RunRIEnumerator(NestLoC(Cancellable.Null)); LogAssert.Expect(LogType.Error, new Regex(".*1 leftover coroutine.*")); cru.gameObject.SetActive(false); Assert.AreEqual(cru.NumRunningCoroutines, 1); yield return(null); }
public void OnCheckIfLevelCanAdvance(Cancellable canceller) { if (canceller.IsCancelled) { return; } var canAdvance = Plugin.AdvanceWhenAllPlayersFinish; foreach (var player in Plugin.Server.ValidPlayers) { if ((player.Car != null && !player.Car.Finished) || DistanceServerMain.UnixTime - player.RestartTime < 30) { canAdvance = false; break; } } if (canAdvance) { Log.Debug($"Advancing because all players with cars have finished."); Plugin.Server.SayChat(DistanceChat.Server("AutoServer:Advancing:Finished", "All players finished. Advancing to the next level in 10 seconds.")); return; } canceller.Cancel(); if (Plugin.AdvanceWhenStartingPlayersFinish) { if (!TimeoutStarted && Plugin.GetUnfinishedStartingPlayersCount() == 0) { LevelEndTime = DistanceServerMain.NetworkTime + 60.0; TimeoutStarted = true; Plugin.SetCountdownTime(Plugin.Server.ModeTime + 60.0); Plugin.Server.SayChat(DistanceChat.Server("AutoServer:Warning:InitialFinished", Plugin.StartingPlayersFinishedMessageGetter())); } } }
// Start is called before the first frame update void Start() { init_Positions(); init_PicsTypes(); //FruitTypes被初始化 //for (int i = 0; i <= 2; i++) // for (int j = 0; j <= 2; j++) // Debug.Log(PicPositions[i][j]); pic_A = null; pic_B = null; pic_A_script = pic_B_script = null; //初始化消除代码 cancelProcess = GetComponent <Cancellable>(); cancelProcess.fruit_types = FruitTypes; //初始化下落动画脚本 fallingProcess = GetComponent <FallingDownAnim>(); //初始化重现创建水果的脚本 recreateProcess = GetComponent <RecreateFruit>(); }
public void TestLoopCancel() { var v = new Vector2(-2, -2); var cors = new Coroutines(); var ct = new Cancellable(); var t0 = Tween.TweenTo(Vector2.Zero, Vector2.One, 2, x => v = x, Easers.ELinear, ct); var tw = TestSteps(t0.Then(t0.Reverse()).Loop(), cors, () => v, new[] { Vector2.Zero, Vector2.One * 0.5f, Vector2.One, Vector2.One * 0.5f, Vector2.Zero, Vector2.One * 0.5f, Vector2.One, Vector2.One * 0.5f, Vector2.Zero, }, VecEq, false); ct.Cancel(CancelHelpers.SoftSkipLevel); //Cancellation requires one step before it is processed Assert.IsFalse(tw.IsCanceled); cors.Step(); Assert.AreEqual(tw.Result, Completion.SoftSkip); }
public static IntPtr GFileQueryInfo(GLib.File file, string attributes, FileQueryInfoFlags flags, Cancellable cancellable) { return(NativeHelper <IntPtr> (() => { IntPtr error; IntPtr info; if (attributes.StartsWith("filesystem::")) { info = g_file_query_filesystem_info(file.Handle, attributes, cancellable == null ? IntPtr.Zero : cancellable.Handle, out error); } else { info = g_file_query_info(file.Handle, attributes, (int)flags, cancellable == null ? IntPtr.Zero : cancellable.Handle, out error); } if (error != IntPtr.Zero) { throw new GException(error); } return info; }, IntPtr.Zero, GIO_NOT_FOUND, string.Format("Failed to query info for '{0}': ", file.Path) + "{0}")); }
private void DoTransition(BackgroundTransition bgt) { if (FromBG == null) { return; } if (ToBG == null) { throw new Exception("Cannot do transition when target BG is null"); } var pb = new MaterialPropertyBlock(); var mat = Instantiate(baseMixerMaterial); float timeout = bgt.TimeToFinish(); var cts = new Cancellable(); transitionCTS.Add(cts); Func <bool>?condition = null; if (bgt.type == BackgroundTransition.EffectType.WipeTex) { bgt.WipeTex.Apply(mat); CombinerKeywords.Apply(mat, CombinerKeywords.WIPE_TEX); } else if (bgt.type == BackgroundTransition.EffectType.Wipe1) { bgt.Wipe1.Apply(mat); CombinerKeywords.Apply(mat, CombinerKeywords.WIPE1); } else if (bgt.type == BackgroundTransition.EffectType.WipeFromCenter) { bgt.WipeFromCenter.Apply(mat); CombinerKeywords.Apply(mat, CombinerKeywords.WIPEFROMCENTER); } else if (bgt.type == BackgroundTransition.EffectType.Shatter4) { Action cb = WaitingUtils.GetCondition(out condition); FromBG.Shatter4(bgt.Shatter4, false, cb); CombinerKeywords.Apply(mat, CombinerKeywords.TO_ONLY); } else if (bgt.type == BackgroundTransition.EffectType.WipeY) { bgt.WipeY.Apply(mat); CombinerKeywords.Apply(mat, CombinerKeywords.WIPEY); //TODO apply these two generics from within the BGT scope. } BackgroundCombiner.SetMaterial(mat, pb); void Finish() { if (!cts.Cancelled) { FinishTransition(); } transitionCTS.Remove(cts); } if (condition == null) { if (timeout > 0) { WaitingUtils.WaitThenCBEvenIfCancelled(this, cts, timeout, false, Finish); } else { throw new Exception("Cannot wait for transition without a timeout or condition"); } } else { WaitingUtils.WaitThenCBEvenIfCancelled(this, cts, timeout, condition, Finish); } }
private void PrepareTimeout(IUIManager?ui, IReadOnlyList <Enemy> subbosses, SMHandoff smh, Cancellable toCancel) { smh.Exec.PhaseShifter = toCancel; var timeout = Timeout; //Note that the <!> HP(hp) sets invulnTime=0. if (props.invulnTime != null && props.phaseType != PhaseType.TIMEOUT) { WaitingUtils.WaitThenCB(smh.Exec, smh.cT, props.invulnTime.Value, false, () => smh.Exec.Enemy.SetVulnerable(Vulnerability.VULNERABLE)); } WaitingUtils.WaitThenCancel(smh.Exec, smh.cT, timeout, true, toCancel); if (props.phaseType?.IsSpell() ?? false) { smh.Exec.Enemy.RequestSpellCircle(timeout, smh.cT); foreach (var subboss in subbosses) { subboss.RequestSpellCircle(timeout, smh.cT); } } //else smh.exec.Enemy.DestroySpellCircle(); if (!props.HideTimeout && smh.Exec.TriggersUITimeout) { ui?.DoTimeout(props.phaseType?.IsCard() ?? false, timeout, smh.cT); } }
public static IEnumerator WaitWhileWithCancellable(Func <bool> amIFinishedWaiting, Cancellable canceller, Func <bool> cancelIf, ICancellee cT, Action done, float delay = 0f) { while (!amIFinishedWaiting() && !cT.Cancelled) { if (delay < ETime.FRAME_YIELD && cancelIf()) { canceller.Cancel(); break; } yield return(null); delay -= ETime.FRAME_TIME; } done(); }
public void OnCheckIfModeCanAdvance(Cancellable canceller) { canceller.Cancel(); }
public void OnCheckIfModeCanStart(Cancellable canceller) { canceller.CancelIf( Plugin.Server.ValidPlayers.FindAll((player) => !player.Stuck && player.HasLoadedLevel(false)).Count == 0 ); }