Created
May 7, 2022 19:49
-
-
Save SMoni/402c630895e1c35fdaa535ad3a5a7fd8 to your computer and use it in GitHub Desktop.
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
const myArray = Array.from({length: 10}, (e, i)=> i) | |
doWork( | |
doSomethingWith, | |
myArray, | |
logToConsole | |
) | |
//Die Funktion, die das Ganze abarbeitet | |
async function doWork(doSomething, anArray, aCallback) { | |
//Mit for(const ... in ...) { ... } geht es | |
for(const entry in anArray) { | |
await doSomething(entry) | |
aCallback(entry) | |
} | |
} | |
//Hier passiert etwas, was länger dauert | |
function doSomethingWith(entry) { | |
console.log(`handling ${entry}`) | |
return new Promise(resolve => setTimeout(resolve, 1000)) | |
} | |
//Das soll ein callback sein | |
function logToConsole(value){ | |
console.log(`done with ${value}`) | |
console.log('--------------------') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment