Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arduino Async Lib #3

Open
timpur opened this issue May 7, 2018 · 6 comments
Open

Arduino Async Lib #3

timpur opened this issue May 7, 2018 · 6 comments

Comments

@timpur
Copy link

timpur commented May 7, 2018

Hi, I'm trying to create a lib for Async style Programing for Arduino. Wondering if you'd be okay for me to pull some ideas from this lib / if you wanted to work with me on this. You have much more knowledge and I'd like to ask for your opinions...

Would be awesome to talk to you, thanks

@NatalieWolfe
Copy link
Member

Hi there! I haven't worked on this project in a long while, but I'm always open to talk. I'm not sure that an event loop model would work well on embedded systems like Arduino. You need a kernel to send signals to your process and schedule it when work is available. I'm not sure that there is a comparable thing in an embedded device. Admittedly my knowledge of Arduino is only at a hobbyist level, so I could be entirely wrong.

You may also want to check out rili, it is basically liblw but people are actually working on it. :)

@timpur
Copy link
Author

timpur commented May 7, 2018

Looked at rili lib and think its complex to port to arduino, but i think bits from this lib can be ported and tweaked to work for arduino. wondering if your willing to work with? Would be nice to get some expert knowledge , as you did design this lib :P.

Also think and event loop model would work alright on arduino, but do we need it? Promise is just an interface, right? does it really need to hooked into the event loop ?

@NatalieWolfe
Copy link
Member

If you would like to fully implement the Promises/A+ spec then you do need an event loop. According to spec the executor (the function passed to new Promise) must be executed synchronously, but the next function (the one passed to .then) must not be executed until the next tick of the loop. This guarantees consistency even when the executor happens to call resolve or reject synchronously. For example, both of these execute the same:

(new Promise((resolve) => {
  console.log('first')
  resolve()
})).then(() => console.log('third'))
console.log('second')

// ----------------------------

(new Promise((resolve) => {
  console.log('first')
  setImmediate(resolve)
})).then(() => console.log('third'))
console.log('second')

Though, I suppose you could have a queue of functions that you iterate over and call at the start of Arduino's loop method. You would have to implement all the dispatching as polling. Damn, now you've intrigued me. :)

@timpur
Copy link
Author

timpur commented May 8, 2018

HEHEH, come on, lets do it :P ive also got bblanchon from https://github.com/bblanchon/ArduinoJson intrigued :P We can do this.

I think we could even use an event loop (striped down).

Also i want to add some more async programing styles like Events (Event Emitter), Tasks, Timeouts, maybe observables, still thinking about things though

@NatalieWolfe
Copy link
Member

I don't have a lot of spare bandwidth between work and my own super secret project, but I'd be down to offer advice and some code when I can. Send me a link to the repo once you've got it started and I'll try to help.

@timpur
Copy link
Author

timpur commented May 9, 2018

In the same boat, thank you :) anything is greatly appreciated.
Will do when I get it set up :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants