Message from JavaScript discussions

May 2019

— You can do fetch('text.txt')
.then(res=>res.txt())
.then(data=>data)
.catch(err=>err)

— 

You use to wait for a promise to be resolved. In node you can use it nicely for file system operations in the browser to fetch any stuff online. You coulf also use it together with setTimeout() to write blocking code with it.

— Its just about promises

— So when the event listener fires how do I prepare a file for later fetching?

— I didn't get to node.js yet

— Edited

— Async await is just a clean way to work with promises. Not having to chain .then().then()

— Thanks for help guys

— Https://hackernoon.com/step-by-step-guide-to-push-your-first-project-on-github-fec1dce574f

— Nice

— You are welcome.
With your game,
You have done async or something close.
You could also do async like this

const doSomethingAsync = () => {
return new Promise(resolve => {
setTimeout(() => resolve('I did something'), 3000)
})
}

const doSomething = async () => {
console.log(await doSomethingAsync())
}
console.log('Before')

doSomething()

console.log('After')


You could try it, modify it and have fun. :)

Message permanent page

— Thanks for the idea