-
Notifications
You must be signed in to change notification settings - Fork 57
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
Promise support #186
Comments
Please note that the thunkify option is undocumented because it is untested, so use it with care. I don't have any plans to add promises, but if it is as simple as writing the thunk support was, then I can look into it. |
Is there any reason you specifically mention bluebird promises, and not ES6 promises? |
I mentioned Bluebird because seeing as how you're using thunkify to convert callbacks to thunks, I figured you'd similarly use a promise library such as Bluebird to |
If there's an easy way to do it, a PR would be great. I added thunks to work with It would probably best to avoid relying on |
+1 for promises |
+1 |
+1 for Promises. Spoiled with async await cant go back to callbacks. |
+1 for Promises as well |
Note that, meanwhile, you can use bluebird's Don't worry, it's non-breaking since you need to append Async to the function name to receive a promise instead of a callback. Here is an example :
|
@alelavoie do you think that using having Totally open for input here, I'm not sure what the best way to go about this is. |
If we consider what promisifyAll do :
I'm not sure it would be a good idea since it would create useless overhead everytime the library is loaded. It would be better to create promisified prototypes or methods directly in the module. |
But then again, it wouldn't be the best solution. I'm not an expert in the matter but the best way to support both promises and callbacks seems to be by building the code with promises and using bluebird's Brief example here : http://stackoverflow.com/questions/23501146/creating-node-library-that-support-both-node-callbacks-and-promise-with-bluebird |
It's a lot more (human) overhead to first manually convent the entire library to promises and then use
I'm not sure that's actually the case. It would happen only once in the lifecycle of the program, on the first require, and only if you require the promisified module. I'm thinking something like |
@jonpacker I agree that converting every async function to promises would be a huge task but it would be the ultimate solution (unless there is a better way of supporting promises and callbacks). You are also right about the fact that the overhead is minimal. I didn't realize that modules were cached after the first time they were loaded, even if you load different instances of them. I guess having promisifyAll built into the library is not as bad as I first thought: we would have a cached version of the promisified module instead of promisifying it every time with That being said, with ES7 Async / Await, promises will become even more important so I think it would be worth it to do a full code migration. |
You don't have to do it all yourself though. If I ever get some free time, would you be open to the idea ? |
+1 |
Hey guys. I've spent a bit of time working on this now. Since neo4j 3 released the "bolt" protocol, I thought it would be a good idea to update seraph to work with it. Since the neo4j javascript driver is promise based, it made sense to make the bolt-based seraph promise based as well. It's a total rewrite, with all functions now cypher based. Feel free to play with it by setting the You can check out a brief breaking-changelog here: lib/bolt/CHANGELOG.md and the source here: lib/bolt/seraph.js Since I just wrote this, you can expect some bugs. A subset of the tests are passing (the ones that make sense to run with bolt, see |
I've just pushed a new version of seraph-model now that works with seraph with |
+1 |
I achieved it by creating promise functions for each api and extending it // neo4j-helper.js
let db = require('seraph');
db.queryPromise = (query, params) => {
return new Promise((resolve, reject) => {
db.query(query, params, (err, res) => {
if(err) reject(err) else resolve(res)
})
})
};
module.exports = db; Then calling it in another file const db = require('./neo4j-helper');
db.queryPromise("MATCH (n:Movie {name:{name}}) RETURN n LIMIT 1", {name: "Star Wars"})
.then(res => {
// handle if success
})
.catch(err => {
// handle if error
}) This is especially useful to me because I can extend it with any functionality I want and use often like for example db.getAllMoviesWatched({email:"[email protected]"})
.then(movies => {
// do stuff with those movies
})
.catch(err => {
// whoops...
}) |
@TarekDeeb sorry that this is so poorly documented, but promise support is already built in if you use the bolt API: const seraph = require('seraph');
const db = seraph({
bolt: true,
server: 'bolt://localhost',
user: 'neo4j',
pass: 'password'
})
db.query(`MATCH (n) RETURN n`).then(r => console.log(r)) I really need to get on making this the standard API, it is way overdue. |
Oh. I see. I just switched to the bolt protocol and stumbled upon this issue. Let me know if you need any help with this. |
So what's the status of this? Are |
I noticed there was a
thunkify
option to return the API using thunks instead of callbacks, which is great, thanks for that! Any thoughts on doing the same and returning bluebird promises? It would be very helpful seeing as how async/await currently favours promises.The text was updated successfully, but these errors were encountered: