Use the new pattern quasiquotation support
This commit is contained in:
parent
f81cf11ebd
commit
a37879695e
|
@ -2,6 +2,7 @@
|
||||||
/// SPDX-FileCopyrightText: Copyright © 2016-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
/// SPDX-FileCopyrightText: Copyright © 2016-2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>
|
||||||
|
|
||||||
import { preserves, Observe, floatValue, Turn, Ref } from "@syndicate-lang/core";
|
import { preserves, Observe, floatValue, Turn, Ref } from "@syndicate-lang/core";
|
||||||
|
import { QuasiValue as Q } from "@syndicate-lang/core";
|
||||||
|
|
||||||
export message type PeriodicTick(intervalMS);
|
export message type PeriodicTick(intervalMS);
|
||||||
export assertion type TimeLaterThan(deadlineMS);
|
export assertion type TimeLaterThan(deadlineMS);
|
||||||
|
@ -19,13 +20,15 @@ export function sleep(ds: Ref, ms: number, cb: () => void): void {
|
||||||
export function boot(ds: Ref) {
|
export function boot(ds: Ref) {
|
||||||
spawn named 'timer/PeriodicTick' {
|
spawn named 'timer/PeriodicTick' {
|
||||||
at ds {
|
at ds {
|
||||||
during Observe(PeriodicTick($intervalMS)) =>
|
during Observe({
|
||||||
spawn linked named (preserves`PeriodicTick(${intervalMS})`) {
|
"pattern": :pattern PeriodicTick(\Q.lit($intervalMS)),
|
||||||
|
"observer": _,
|
||||||
|
}) => spawn linked named (preserves`PeriodicTick(${intervalMS})`) {
|
||||||
const thisFacet = Turn.activeFacet;
|
const thisFacet = Turn.activeFacet;
|
||||||
thisFacet.preventInertCheck();
|
thisFacet.preventInertCheck();
|
||||||
const handle = setInterval(() => thisFacet.turn(() => {
|
const handle = setInterval(() => thisFacet.turn(() => {
|
||||||
send message PeriodicTick(intervalMS);
|
send message PeriodicTick(intervalMS);
|
||||||
}), floatValue(intervalMS as any));
|
}), floatValue(intervalMS));
|
||||||
on stop clearInterval(handle);
|
on stop clearInterval(handle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,11 +36,13 @@ export function boot(ds: Ref) {
|
||||||
|
|
||||||
spawn named 'timer/TimeLaterThan' {
|
spawn named 'timer/TimeLaterThan' {
|
||||||
at ds {
|
at ds {
|
||||||
during Observe(TimeLaterThan($deadlineMS)) =>
|
during Observe({
|
||||||
spawn linked named (preserves`TimeLaterThan(${deadlineMS})`) {
|
"pattern": :pattern TimeLaterThan(\Q.lit($deadlineMS)),
|
||||||
|
"observer": _,
|
||||||
|
}) => spawn linked named (preserves`TimeLaterThan(${deadlineMS})`) {
|
||||||
const thisFacet = Turn.activeFacet;
|
const thisFacet = Turn.activeFacet;
|
||||||
thisFacet.preventInertCheck();
|
thisFacet.preventInertCheck();
|
||||||
let delta = floatValue(deadlineMS as any) - (+(new Date()));
|
let delta = floatValue(deadlineMS) - (+(new Date()));
|
||||||
let handle: any | null = setTimeout(() => thisFacet.turn(() => {
|
let handle: any | null = setTimeout(() => thisFacet.turn(() => {
|
||||||
handle = null;
|
handle = null;
|
||||||
react {
|
react {
|
||||||
|
|
Loading…
Reference in New Issue