Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

Promise interface? #58

Closed
ericclemmons opened this issue Apr 12, 2017 · 7 comments
Closed

Promise interface? #58

ericclemmons opened this issue Apr 12, 2017 · 7 comments

Comments

@ericclemmons
Copy link

I haven't been able to use https://github.com/sindresorhus/pify successfully with this library (this binding issues?), but I was wondering if, in absence of a callback, method calls could return a Promise so that we can use async & await.

Sounds cool, right!? ;)

@dlau
Copy link
Contributor

dlau commented Apr 20, 2017

Hi Eric, thanks for your report. I'm looking into your issue with using https://github.com/sindresorhus/pify .

Will discuss with the team about a promise interface. At first glance, it sounds like a great feature enhancement.

@dlau
Copy link
Contributor

dlau commented Apr 21, 2017

Hi Eric,

With regard to your issue using https://github.com/sindresorhus/pify, we use this internally in our library, you can use our library functions by explicitly binding the instance to the function you pass to pify:

Callback style:

ld_client.variation.("myflag", user, false, (err, show_feature) => {
...
}

Wrapped in pify:

pify(ld_client.variation.bind(ld_client))("myflag", user, false).then(show_feature => {
...
})

Link to related issue in pify repo:
sindresorhus/pify#23

@dlau dlau removed the bug label Apr 21, 2017
@apucacao
Copy link
Contributor

Hi @ericclemmons ,

I wanted to let you know we finally released version 3.1.0 in which asynchronous methods return a Promise. The callbacks for those methods are now entirely optional.

Let me know if you have any questions or feedback. :)

Best,
Alexis

@yamoo
Copy link

yamoo commented Jan 23, 2018

Hi @apucacao,
I have tried Promise way with variation method but I couldn't receive the flag value on the args of then. It returns undefined. I also checked the promise value returned by the variation method with console.log. It shows Promise { undefined } on my terminal. Do you have any advices for that? I'm using Node v8.7.0 and ldclient-node v3.3.0.

client.waitUntilReady().then(() => {
  var promiss = client.variation("flag", user, false)
  promiss.then((value) => {
    console.log(promiss, value); // Promise { undefined } undefined
  });
});

Thank you.

@apucacao
Copy link
Contributor

Hi @yamoo !

Sorry about that — there's a bug in the the code. I filed #75 and we'll release a bug fix version shortly.

I'll let you know once I've released the fix.

Thanks for your patience!
Alexis

@apucacao
Copy link
Contributor

@yamoo I just released version 3.3.1 which includes a fix for the bug you found. Thanks for reporting it and sorry for the inconvenience!

@yamoo
Copy link

yamoo commented Jan 24, 2018

@apucacao Thank you for the quick response! I could confirm it was fixed by upgrading to v3.3.1.

eli-darkly added a commit that referenced this issue Mar 14, 2018
avoid race condition by serializing all Redis updates
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants