Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

Promisify nedb & request #8

Open
anonrig opened this issue Apr 26, 2017 · 3 comments
Open

Promisify nedb & request #8

anonrig opened this issue Apr 26, 2017 · 3 comments

Comments

@anonrig
Copy link

anonrig commented Apr 26, 2017

Because of the lack of bluebird in this library, you had to promisify nedb from scratch. But basically, you could have used Promise.promisifyAll(Datastore.prototype);.

On the other hand, request-promise library already promisifies request library.

@cagataycali
Copy link
Owner

First of all thank you very much for your contribution, It made me happy to share your information with me.

  • Promise.promisifyAll(Datastore.prototype);
    I'm asking because I do not really know. Does this solution solve it literally? This method will provide a more legible spelling/understanding if it really works completely. I did not examine this database in detail when I wrote the project.

On the other hand, I did not do that because the second solution will add extra dependency. request-promise

If you have any other ideas, I would like to talk and discuss fondly.

Thank you again for your contribution.
Çağatay

@anonrig
Copy link
Author

anonrig commented Apr 26, 2017

It's proven in the past that Bluebird's (https://github.com/petkaantonov/bluebird) Promise implementation is faster than the actual Promise in NodeJs.

Following code will promisify all functions that include callbacks. Therefore you don't need to do return new Promise((res, rej) every time.

const Promise = require('bluebird');
Promise.promisifyAll(Datastore.prototype);

For example: you can just use the following code:

return this.categories.findOne({name: obj.category});

On the other hand using Bluebird will enable this function:

quiet() {
    return new Promise(resolve => {
      this.slient = !this.slient;
      resolve(slient);
    });
  }

to be replaced by this:

quiet() {
  this.slient = !this.slient;
  return Promise.resolve(this.slient);
}

On the other hand, when promisifying an actual class/function that you didn't write from scratch, developers tend to make mistakes. Therefore, adding request-promise will have more benefits for the library in the long term.

But again, it's your choice.
Best.

@cagataycali
Copy link
Owner

I'll rewrite lazy with your instructions in few days
Thanks your advices 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants