TelluIoT / ThingML

The ThingML modelling language
https://github.com/TelluIoT/ThingML
Apache License 2.0
101 stars 32 forks source link

The brower compiler uses the non standard setImmediate #247

Closed fungiboletus closed 5 years ago

fungiboletus commented 5 years ago

setImmediate is a non-standard method only available in Internet Explorer, Edge, and NodeJS. Polyfils such as YuzuJS/setImmediate or core-js do exist. A setTimeout could be used instead, but it may have a 4ms delay.

requestIdleCallback and requestAnimationFrame are also alternatives to consider but probably not always relevant.

MDN documentation about setImmediate.

brice-morin commented 5 years ago

OK, I will double-check, but I thought we replaced setImmediate with setTimeout for the browser...

brice-morin commented 5 years ago

@fungiboletus if you have some snippets of generated code where is appears, feel free to mention it in this issue

fungiboletus commented 5 years ago

Hei @brice-morin

thing HelloThing {
    statechart HelloWorld init Greetings {
        state Greetings {
            transition -> Bye action print "Hello World!\n"
        }
        final state Bye {
            on entry print "Bye.\n"
        }
    }
}

configuration HelloCfg {
    instance my_instance: HelloThing
}
fungiboletus commented 5 years ago
HelloThing.prototype.build = function(session) {
    /*State machine (states and regions)*/
    /*Building root component*/
    this._statemachine = new StateJS.StateMachine('HelloWorld');
    let _initial_HelloThing_HelloWorld = new StateJS.PseudoState('_initial', this._statemachine, StateJS.PseudoStateKind.Initial);
    let HelloThing_HelloWorld_Greetings = new StateJS.State('Greetings', this._statemachine);
    let HelloThing_HelloWorld_Bye = new StateJS.FinalState('Bye', this._statemachine).entry(() => {
        console.log(''+'Bye.\n');
        🚨 setImmediate(()=>this._stop()); 🚨
    });
    _initial_HelloThing_HelloWorld.to(HelloThing_HelloWorld_Greetings);
    HelloThing_HelloWorld_Greetings.to(HelloThing_HelloWorld_Bye).effect(() => {
        console.log(''+'Hello World!\n');
    });
}
brice-morin commented 5 years ago

ah yes, in final states...

brice-morin commented 5 years ago

So something like: setTimeout(()=>this._stop(),0); instead?

fungiboletus commented 5 years ago

Yes, it works with this fix.