TelluIoT / ThingML

The ThingML modelling language

Home Page:https://github.com/TelluIoT/ThingML

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The brower compiler uses the non standard setImmediate

fungiboletus opened this issue · comments

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.

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

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

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
}
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');
	});
}

ah yes, in final states...

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

Yes, it works with this fix.