Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Prototype async node-ffi #9

Closed
nebrius opened this issue Jun 1, 2015 · 2 comments
Closed

Prototype async node-ffi #9

nebrius opened this issue Jun 1, 2015 · 2 comments

Comments

@nebrius
Copy link
Contributor

nebrius commented Jun 1, 2015

node-ffi holds a lot of promise for eliminating the need for native code for modules, but there is one aspect that makes it less than ideal: everything is synchronous.

The C/C++ way of doing async programming is typically to spin up a background thread, but we don't have threading in JS. We could use something like cluster, but that approach isn't as efficient as threading.

So let's prototype what an node-ffi would look like with async capabilities baked in.

@TooTallNate
Copy link

For the record, node-ffi does expose an .async() function on every ForeignFunction instance, which invokes the function on the libuv thread pool. See https://github.com/node-ffi/node-ffi/blob/master/lib/_foreign_function.js#L65-L118

I'm also in the process of moving the core, low-level pieces of ref/node-ffi into io.js. It's a slow, tedious process since there's a lot to cover, but see nodejs/node#1750, nodejs/node#1759 and nodejs/node#1762 (and a 4th for libffi itself next) if you want to follow the progress of that (basically the ffi label in the issue tracker).

@nebrius
Copy link
Contributor Author

nebrius commented Jun 1, 2015

That's amazing @TooTallNate! I seriously had no idea there was an .async() function. Guess that's what I get for filing this issue before digging through the code 😅

I think this could be a huge win for NodeBots especially since a lot of people doing hardware are beginners, and native modules can be a big barrier to entry.

Thanks for all your work getting ffi into core, I'll certainly be keeping an eye on things. If there's anything the Hardware WG can do to help, let us know!

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

No branches or pull requests

2 participants