Created
July 20, 2017 02:44
-
-
Save helton/57632ff34101153d8bfa1cd4c25156aa to your computer and use it in GitHub Desktop.
Full Stack Academy - Aula 01 - Exercicio 03
This file contains 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
/* | |
* [Exercício 3] | |
* | |
* Dado que a assinatura da função readdir do módulo fs é: | |
* | |
* | |
* const fs = require('fs') | |
* const path = './' | |
* fs.readdir(path, (err, files) => { | |
* if(err){ | |
* console.log('ocorreu um erro.') | |
* }else{ | |
* console.log(files) | |
* } | |
* }) | |
* | |
* Construa uma versão desta função promisified, ou seja, que retorne uma promise. | |
* (Será possível chamá-la da seguinte forma: readdirPromise(path).then((files)=> console.log(files)) ) | |
*/ | |
const fs = require('fs') | |
const readdirPromise = (path) => new Promise((resolve, reject) => | |
fs.readdir(path, (err, files) => | |
err ? reject(err) : resolve(files) | |
) | |
) | |
readdirPromise('./').then((files)=> console.log(files)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Certinho.