Open jrgleason opened 9 years ago
@jrgleason Try this using bluebird Promises
Promise.map(regulation.sources, function(source) {
return mergeSourceAsync(source,transaction)
},{concurrency:1}).then(function(value) {
// commit
}).catch(function(error) {
// rollback
})
Easiest to handle this using async/await or coroutines/yield. I'm also assuming that you'll either promisify mergeSource() using bluebird or manually construct a quick wrapper around it so that it returns a promise instead of firing a callback.
(Edit for future readers:) Note the addition of {concurrency: 1} as an option, which ensures only one element of the array is executed at a time until its promise resolves.
Right but I am pretty sure this doesn't work in a transaction since you are not waiting for the previous call to finish. This is why I needed to remove my promises
Ahh nm missed the concurrency thing at the end. Interesting.
Yes, that's definitely the kicker. It'll make sure every promise is executed sequentially. It's great fun :-)
Sorry for the delay folks. Glad to hear you're unblocked for now.
As mentioned in https://github.com/thingdom/node-neo4j/issues/164#issuecomment-142730727:
You have an interesting and good point that node-neo4j could queue the queries under the hood. I hesitate with something like that though, as part of node-neo4j's goals is to be transparent. It feels like it's worth knowing that the queries aren't running concurrently, rather than node-neo4j hiding that.
Curious what you guys think?
Currently if try an async thread loop firing off Cypher requests Neo4J barfs saying 'you are trying to run requests while another is running'.
My work around for now is using the asynch library....
It would be nice if there was a way to handle this in node-neo4j