async function doTasks(tasks = [])
// Do some concurrent stuff:
let results = await Promises.all(tasks.map((task) => new Promise((resolve, reject) => {
workerpool.exec('mytask', [task])
.then(function(result) {
resolve(result)
})
.catch(function(err) {
reject(err)
})
})))
// Function pauses here until all tasks resolve.
// do stuff with results
}
The workerpool exists outside the scope of this function, is that kind of the crux of the distinction, or does it come down to how threads / workers are managed (by the language / first class constructs) that outlines the definition of structured concurrency?The example above feels like a similar pattern to what I've seen in discussions of structured concurrency but as with most things I feel like there's an aha moment where I'll get what all the fuss is about.