Skip to content

Instantly share code, notes, and snippets.

@etale
Last active February 19, 2016 00:56
Show Gist options
  • Save etale/b78fae2a327a6c93dd7d to your computer and use it in GitHub Desktop.
Save etale/b78fae2a327a6c93dd7d to your computer and use it in GitHub Desktop.
Oneliner Promisify
var promisify = (a) => (...b) => new Promise((c, d) => a(...b, (e, f) => e ? d(e) : c(f)))
@etale
Copy link
Author

etale commented Feb 17, 2016

// Rest parameters + Spread operator
var promisify = (a) => (...b) =>
  new Promise((c, d) =>
    a(...b, (e, f) => e ? d(e) : c(f)))

@etale
Copy link
Author

etale commented Feb 18, 2016

// Spread operator only
var promisify = (a) => function () {
  return new Promise((c, d) =>
    a(...arguments, (e, f) => e ? d(e) : c(f)))
}

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