From babb858ce2ce41cb876c802d0afdfec0b0a4b4d1 Mon Sep 17 00:00:00 2001 From: Daniel Ramos Date: Wed, 13 Dec 2017 12:15:39 +0000 Subject: [PATCH] Moving semicolon, changing example in promisify.md --- snippets/promisify.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/snippets/promisify.md b/snippets/promisify.md index d6b437589..f9516aeed 100644 --- a/snippets/promisify.md +++ b/snippets/promisify.md @@ -1,15 +1,14 @@ ### Promisify -Creates a promisified version of the given callback-style function. In Node 8+, you -can use [`util.promisify`](https://nodejs.org/api/util.html#util_util_promisify_original) +Use currying to return a function returning a Promise that calls the original function. Use the rest operator to pass in all the parameters. In Node 8+, you can use [`util.promisify`](https://nodejs.org/api/util.html#util_util_promisify_original) ```js const promisify = func => (...args) => new Promise((resolve, reject) => func(...args, (err, result) => - err ? reject(err) : resolve(result)); - ) -// const stat = promisify(fs.stat) -// stat('foo.txt') -> Promise resolves if `foo.txt` exists, otherwise rejects + err ? reject(err) : resolve(result)) + ); +// const delay = promisify((d, cb) => setTimeout(cb, d)) +// delay(2000).then(() => console.log('Hi!')) -> Promise resolves after 2s ```