Skip to content

Commit

Permalink
[node] Switch to setImmediate to avoid starving the Node.js event loop
Browse files Browse the repository at this point in the history
  • Loading branch information
segevfiner authored Feb 22, 2024
1 parent 3bdb10d commit e8ef258
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions js/node/lib/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class OnnxruntimeSessionHandler implements InferenceSessionHandler {
async run(feeds: SessionHandler.FeedsType, fetches: SessionHandler.FetchesType, options: InferenceSession.RunOptions):
Promise<SessionHandler.ReturnType> {
return new Promise((resolve, reject) => {
process.nextTick(() => {
setImmediate(() => {
try {
resolve(this.#inferenceSession.run(feeds, fetches, options));
} catch (e) {
Expand All @@ -56,7 +56,7 @@ class OnnxruntimeBackend implements Backend {
async createInferenceSessionHandler(pathOrBuffer: string|Uint8Array, options?: InferenceSession.SessionOptions):
Promise<InferenceSessionHandler> {
return new Promise((resolve, reject) => {
process.nextTick(() => {
setImmediate(() => {
try {
resolve(new OnnxruntimeSessionHandler(pathOrBuffer, options || {}));
} catch (e) {
Expand Down

0 comments on commit e8ef258

Please sign in to comment.