node-threads-a-gogo
node-threads-a-gogo copied to clipboard
receiving event blocks promise resolution
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.