Skip to content

Instantly share code, notes, and snippets.

@helton
Created July 20, 2017 02:44
Show Gist options
  • Save helton/57632ff34101153d8bfa1cd4c25156aa to your computer and use it in GitHub Desktop.
Save helton/57632ff34101153d8bfa1cd4c25156aa to your computer and use it in GitHub Desktop.
Full Stack Academy - Aula 01 - Exercicio 03
/*
* [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))
@tuliofaria
Copy link

Certinho.

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