TelluIoT / ThingML

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

0ms timer from STL are ignored #271

Closed fungiboletus closed 5 years ago

fungiboletus commented 5 years ago

timer!timer_start(...,0) are ignored because the standard implementation ignores 0ms or negative timeouts (event m : timer?timer_start guard m.delay > 0). Should it be replaced by >= 0 ?

ffleurey commented 5 years ago

Should be fixed and deployed. Let me know if it works.

ffleurey commented 5 years ago

Does not seem to work in JS. To be tested also on the other platforms.

brice-morin commented 5 years ago

Works with Node.JS (I haven't tested for the browser)

brice-morin commented 5 years ago

Works with Java and Go, too

fungiboletus commented 5 years ago

My guess : it's a conflict in the JS browser between the various implementations of setImmediate and the setTimeout of 0ms. I fixed by asking a timeout of 1ms minimum in before calling the timer.

ffleurey commented 5 years ago

We could consider putting the 1ms hack in the library. i.e. replace the 0 with a 1. It is not acceptable to not get a timeout message after you have started a timer, but we never give guaranty exactly when you will get the message.

brice-morin commented 5 years ago

Can't we just send the timeout message right away, without actually starting a JS timer with a 0ms period? Or do we need to rely on some side-effects of actually starting the JS timer?

fungiboletus commented 5 years ago

I think in the ThingML context I would not expect to get the javascript side effect, just the timer to execute… so Yes right away is fine :-)

brice-morin commented 5 years ago

Makes sense to me :-) I will test that out and commit if it indeed works

brice-morin commented 5 years ago

That strategy should now be implemented for all timers in the STL