Timeline for Working with async in node.js
Current License: CC BY-SA 3.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Aug 14, 2013 at 17:40 | vote | accept | Colin | ||
| Aug 14, 2013 at 8:35 | comment | added | slebetman | There's no process.fork that I'm aware of. There is however child_process.fork() and child_process.spawn() which launches another instance of node.js that you can then run your blocking code in and communicate via pipes. You can probably use the to write async wrappers around sync code. Also as mentioned there are several threading libraries for node.js if you prefer to use threads instead of full processes. Just search for "thread" on npm. | |
| Aug 13, 2013 at 19:55 | comment | added | Colin |
Also can I use process.fork() ?
|
|
| Aug 13, 2013 at 19:32 | comment | added | Colin | Interesting. Is there node modules out there that help make things truly asynchronous? | |
| Aug 13, 2013 at 19:25 | comment | added | slebetman | All that will do is wait roughly 1ms (or 10ms, depends on your OS's tick) and then execute the long sync function which will then block all other code from executing. Yes, it prevents it from blocking it now so that you can run other code first but it doesn't prevent it from blocking. | |
| Aug 13, 2013 at 18:35 | comment | added | Colin |
Can't I just wrap it in a function which calls the long sync function using process.nextTick(long_sync_io_function)?
|
|
| Aug 13, 2013 at 18:17 | comment | added | slebetman | Yes. For wrappers, you can't convert a monolithic long sync functions to async in pure javascript. You'll need to use threading libraries (which are themselves implemented in C) or write a wrapper in C using the node API and use pthreads. The only way to convert sync code to async in pure javascript is to break up the inner loop into recursive calls to setTimeout(). | |
| Aug 13, 2013 at 18:14 | history | edited | slebetman | CC BY-SA 3.0 |
added 996 characters in body
|
| Aug 13, 2013 at 18:10 | comment | added | Colin |
OK. So if long_sync_io_function() came from a 3rd party module, I'd still need to create my own long_async_io_function() wrapper function then use async
|
|
| Aug 13, 2013 at 18:03 | history | answered | slebetman | CC BY-SA 3.0 |