UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

44 lines (35 loc) 988 B
import { Behavior } from "../Behavior.js"; import { BehaviorStatus } from "../BehaviorStatus.js"; export class PromiseBehavior extends Behavior { /** * * @param {()=>Promise} factory */ constructor(factory) { super(); /** * * @type {function(): Promise} * @private */ this.__factory = factory; this.__promise = null; this.__promise_state = BehaviorStatus.Running; } initialize(context) { super.initialize(context); this.__promise = this.__factory(); this.__promise_state = BehaviorStatus.Running; this.__promise.then( () => { this.__promise_state = BehaviorStatus.Succeeded; }, () => { this.__promise_state = BehaviorStatus.Failed; } ); } tick(timeDelta) { return this.__promise_state; } }