Created
October 25, 2017 06:33
-
-
Save andrIvash/cedb0a97a4912eed1a5c3c655581f215 to your computer and use it in GitHub Desktop.
nano delay by https://github.com/ai
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Resolves a Promise after a specified amount of time. | |
| * | |
| * @param {number} delay Milliseconds to wait before resolving. | |
| * @param {any} value Argument to be resolved by this Promise. | |
| * | |
| * @return {Promise} Promise which will be resolved after passed time. | |
| * | |
| * @example | |
| * const delay = require('nanodelay') | |
| * | |
| * delay(300, "foo").then(result => { | |
| * // Executed after 300 milliseconds | |
| * result //=> "foo" | |
| * }) | |
| * | |
| * @name nanodelay | |
| */ | |
| module.exports = function (delay, value) { | |
| return new Promise(function (resolve) { | |
| setTimeout(resolve, delay, value) | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment