Created
June 8, 2017 02:42
-
-
Save alanhoff/879522c1af431db75914a20f349c9918 to your computer and use it in GitHub Desktop.
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
var semaforo = 0 | |
var valores = ['hello', 'world'] | |
function callback () { | |
semaforo-- | |
if (semaforo === 0) { | |
console.log('Acabou tudo o que tinha pra fazer, vou finalizar') | |
process.exit() | |
} else { | |
console.log('Ainda tem trabalho pra fazer') | |
} | |
} | |
valores.forEach(function (valor) { | |
// Eu indico a quantidade de trabalho que está pendende | |
// ao incrementar o semáforo | |
semaforo++ | |
// Esse setTimeout serve apenas para emular uma função | |
// assíncrona neste exemplo | |
setTimeout (callback, 500) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment