Skip to content

Instantly share code, notes, and snippets.

@juukie
Created October 5, 2017 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juukie/2e72cc2093d7c3511907823857924818 to your computer and use it in GitHub Desktop.
Save juukie/2e72cc2093d7c3511907823857924818 to your computer and use it in GitHub Desktop.
Promise takeAtLeast
// Add takeAtLeast method to Promise
/* eslint no-unused-vars: 0 */
Promise.prototype.takeAtLeast = function (time) {
return new Promise((resolve, reject) => {
const limiter = new Promise((resolve, reject) => {
setTimeout(resolve, time);
})
Promise.all([this, limiter]).then(([response, _]) => {
resolve(response)
}, reject)
})
}
@juukie
Copy link
Author

juukie commented Oct 5, 2017

Taken from a tweet from Adam Wathan

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