node-threads-a-gogo icon indicating copy to clipboard operation
node-threads-a-gogo copied to clipboard

receiving event blocks promise resolution

Open NodeGuy opened this issue 8 years ago • 0 comments

TAGG: 0.1.13 Node.js: v6.9.5

Check out this strange code:

'use strict'

const tagg = require('threads_a_gogo')

const thread = tagg.create()

const promise = new Promise((resolve) => {
  thread.on('event', resolve)
  thread.eval(`thread.emit('event', 42)`)
})

promise.then(console.log)

// Without this the promise never resolves.
setImmediate(() => {})

If I don't include setImmediate(() => {}) at the end then the promise never resolves and doesn't print 42 to the console. It looks like the main event loop isn't being processed after receiving an event until I kick it with a null setImmediate.

NodeGuy avatar Apr 16 '17 17:04 NodeGuy