Considering support run async func in worker thread?
See original GitHub issueIt seems that ThreadWorker
can only accept sync function as args at present. What if provide an options.async
, when it sets to be true, then exec async function.
example:
'use strict'
const { ThreadWorker } = require('poolifier')
async function yourFunction (data) {
return new Promise((resolve, reject) => {
resolve(1)
})
}
module.exports = new ThreadWorker(yourFunction, { async: true, maxInactiveTime: 60000 })
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Multiple worker threads vs One worker with async/await
The work is mostly IO bound. async lambda with trackedTasks works. I have var t = Task.Run(async lambda); trackedTasks.Add(t); t.ContinueWith( ...
Read more >Working with threads — AnyIO 3.6.2 documentation
Such operations would normally block the asynchronous event loop, leading to performance issues. The solution is to run such code in worker threads....
Read more >Task asynchronous programming model - Microsoft Learn
The method runs on the current synchronization context and uses time on the thread only when the method is active. You can use...
Read more >w3reality/async-thread-worker - GitHub
async -thread-worker presents an abstraction of Web Worker thread communication based on the client-server model. Supported features are:.
Read more >Introducing asynchronous JavaScript - Learn web development
Here, makeGreeting() is a synchronous function because the caller has to wait for the function to finish its work and return a value...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Version 1.1.0 is released , I will close this issue . Let me know if everything is ok and thanks to contribute on this project !!!
In my use case, I use vm2 to run user’s custom code(like google app scripts). And the vm2 is not isolated, so I need to run in worker threads. And the script may contains async func.
Here is an example: