-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
document alternative solution like worker_threads
or child_process
#145
Comments
|
@JounQin I am very interested in it but can your solution do the exact same thing with callbacks? Can it do e.g. proper sleep()? Also is synced code executed in the same scripting context? |
@jardicc I'm not sure what's meaning, the The transformed function is executed in
See https://github.com/rx-ts/synckit/blob/main/test/worker-esm.ts |
@JounQin Ok. Thanks. For me, this could have huge potential. But it requires careful research from my side. Do you think that would be this possible to use sync WebSocket communication? Don't judge me... I have very good reasons to do so and I am not running a webserver. |
If you can wrap it into a I don't know if it is something you want like: // worker.js
const ws = new WebSocket()
let _resolve
let _reject
let loadWs = new Promise((resolve, reject) => {
_resolve = resolve
_reject = reject
})
let value
ws.on('data', (data) => {
value = data
_resolve()
})
we.once('error', _reject)
runAsWorker(async () => {
await loadWs
return value
}) // runner.js
const syncFn = createSyncFn(require.resolve('./worker'))
syncFn() // will wait for first ws loaded value and always get latest value |
@JounQin Ok, that is interesting... thanks for the inspiration to experiment with. In your example is client-side I think. Meanwhile, right now I do have "server" side in NodeJS. But since I have 1:1 connection maybe I could reverse it... but I would prefer not to do so since it requires more time to implement. :-D |
worker_threads
is almost fast same as current solution but requires no node bindings ornode-gyp
, whilechild_process
is extremely slower.See benchmark at https://github.com/rx-ts/synckit/blob/main/benchmarks/benchmark.esm.txt
The text was updated successfully, but these errors were encountered: