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

Resolve an interesting case #18

Closed
tunnckoCore opened this issue Mar 22, 2017 · 1 comment
Closed

Resolve an interesting case #18

tunnckoCore opened this issue Mar 22, 2017 · 1 comment

Comments

@tunnckoCore
Copy link
Member

tunnckoCore commented Mar 22, 2017

When for example, there is done argument, but is not called, and there is a result which is a promise.

something like

if (isAsyncFn && !called && isPromise(syncResult)) {
  resolve(syncResult)
}

https://github.com/hybridables/redolent/blob/master/index.js#L117-L124

edit:

this seems to fix it

      if ((!isAsyncFn && !called) || (isAsyncFn && !called && isPromise(syncResult))) {
        resolve(syncResult);
      }

i think we should handle this case, in that way. It is a lot better to auto-magically do it, instead of returning rejected promise that signals the user that he didn't called the done callback argument.

@tunnckoCore
Copy link
Member Author

tunnckoCore commented Mar 22, 2017

examples

var promisify = require('redolent')

var fn = promisify(function (app, done) {
  if (app.aaa === 1) {
    done(null, 111)
    return
  }
  return Promise.resolve(123 + app.aaa)
})

fn({ aaa: 2 }).then(console.log) // => 125
// or
fn({ aaa: 1 }).then(console.log) // => 111

both work

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

No branches or pull requests

1 participant