avocado-old/packages/behavior/context/timing.hooks.js

40 lines
632 B
JavaScript

import {TickingPromise} from '@avocado/core';
class Timing {
static wait (duration) {
return new TickingPromise(
() => {},
(elapsed, resolve) => {
duration -= elapsed;
if (duration <= 0) {
resolve();
}
},
);
}
}
export function behaviorContextTypes() {
return {
Timing: {
wait: {
type: 'void',
label: 'Wait for $1 seconds.',
args: [
['duration', {
type: 'number',
}],
],
},
},
};
}
export function behaviorContextGlobals() {
return {
Timing: [Timing, 'Timing'],
};
}