- Tipos de variáveis, escopo e closures (
var,let,const, escoposfunctione{}) - Tipos e coerção (
Boolean,null,undefined,Number,String,Object,Symbole tabela de coerção) this,prototypes e classes- Assincronia (
event loop,setTimeout,setInterval,setImmediate,process.nextTick,Promise,function*,coroutines easyncawait)
Created
May 21, 2019 14:57
-
-
Save evaporei/9969c5a8af59f88bf670408e505b3a8f to your computer and use it in GitHub Desktop.
Aula JS
Author
evaporei
commented
Jun 6, 2019
Author
Vídeos sobre event loop:
https://www.youtube.com/watch?v=8aGhZQkoFbQ
https://www.youtube.com/watch?v=zphcsoSJMvM
Author
Node.js event loop:
https://nodejs.org/en/docs/guides/event-loop-timers-and-nexttick
Author
Explicar:
new PromisethencatchPromise.resolvePromise.rejectPromise.all
Author
const fs = require('fs')
fs.readFile('request_tables.js', 'utf-8', (error, arquivo) => {
if (error) {
return
}
console.log('arquivo', arquivo)
})
function readFilePromise (fileName) {
return new Promise((resolve, reject) => {
fs.readFile(fileName, 'utf-8', (error, arquivo) => {
return reject(new Error('deu ruim pra ler o arquivo'))
if (error) {
return reject(error)
}
return resolve(arquivo)
})
})
}
readFilePromise('request_tables.js')
.catch((error) => {
console.log('catch', error)
return Promise.resolve(2)
})
.then(valor => console.log('valor', valor))
// db.algumaCoisa()// errado
// .catch()
// .then()
// resolve
// fulfill
// reject
const um = () => Promise.resolve(1)
const dois = () => Promise.resolve(2)
Promise.all([um(), dois()])
.then(([one]) => console.log('valores', one))
.catch(error => console.log('error', error))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment