WebWorkers?

Posted on
  • I am looking to have simultaneous execution of tasks and I am wondering if anyone has considered implementing web workers?

    Specifically, I need to monitor a pin and activate a motor while sending data to a sound board over serial. However, I want the motor to stop when the pin is no longer triggered but have the sound continue.
    Additionally, I would like to be able to asynchronously send data over wifi without interrupting the previous two tasks. I can see how the first one might be combined into one task with careful control of looping, but the second task will probably not be possible in the same cycle.

    If I had something like a web worker, I could control the three tasks independently and trigger them when the appropriate event is detected.

  • Hi, I'm afraid proper multitasking isn't going to happen - there's not enough memory for two execution stacks.

    The way Espruino works, you execute code on events. So when a pin changes state it executes code which starts or stops your motor. The WiFi works the same way so you'll find that if you write your code in an Espruino-friendly way (eg. not while (true) ...) everything will 'just work'.

    Having said that I'm not sure you'll have much luck streaming sound data I'm afraid (multitasking or not) because of general RAM/speed issues in Espruino.

  • I will have to see how it turns out. I saw an open enhancement somewhere (github?) that suggested opening a file as a stream so that we don't need to read the entire file into memory in order to read the contents of the file. I might have to do that in order to get the data moved around.

  • Ahh - probably this one? https://github.com/espruino/Espruino/issues/12

    With the web server, being able to stream from a file would be a massive help...

  • That's the one. I have been looking over the source in prep for doing something like this.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

WebWorkers?

Posted by Avatar for cephdon @cephdon

Actions