Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling for multiple events in a transaction #172

Open
jrgleason opened this issue Sep 24, 2015 · 5 comments
Open

Better handling for multiple events in a transaction #172

jrgleason opened this issue Sep 24, 2015 · 5 comments
Labels
Milestone

Comments

@jrgleason
Copy link

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....

async.eachSeries(regulation.sources, function iterator(source, callback){
    mergeSource(source, transaction, callback);
}, function(err){
    if(err){
      transaction.rollback("Problem adding source");
      throw err;
    }
    transaction.commit(function () { });
}); 

It would be nice if there was a way to handle this in node-neo4j

@hilkeheremans
Copy link

@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.

@jrgleason
Copy link
Author

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

@jrgleason
Copy link
Author

Ahh nm missed the concurrency thing at the end. Interesting.

@hilkeheremans
Copy link

Yes, that's definitely the kicker. It'll make sure every promise is executed sequentially. It's great fun :-)

@aseemk
Copy link
Member

aseemk commented Oct 12, 2015

Sorry for the delay folks. Glad to hear you're unblocked for now.

As mentioned in #164 (comment):

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?

@aseemk aseemk added this to the v2 redesign milestone Oct 12, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants