-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Promises #9
Comments
I'd argue that async/await is less confusing - especially if you don't know that they're actually promises. If everything is async/await it simplifies a lot of code. await UW.init(...)
let player = (...)
await waitSeconds(5) // etc |
Interesting thought. Can |
No. You'd have to do: import 'you-win' as UW
async function main() {
await UW.init()
// ...
}
main().catch(console.error) Which I'd argue is fairly ugly. You could do: import 'you-win' as UW
UW.init(...).then(async () => {
// ...await foo()
}).catch(console.error) // not sure if you need this in browsers? Which is almost the same as the current recommended way of initialising, except it has an |
Or, if the game itself could be considered a module (this allows us to easily have an actual restart() method, too!) import 'you-win' as UW
export async function main() {
await UW.init()
// ...
} And then we somehow dynamically import that script (babel in the browser??) and execute main(). |
Aw. :( An export is an interesting idea, though I don't think it's required in order to have a restart() method... |
Proposal:
forever
andSound.play
should return aPromise
. That way, you can do stuff after they finish.Example for
forever
:sound.play().then(() => { … })
would act like "play sound and wait" from Scratch.My concern is that introducing Promises really complicates the concept of control flow—because they're a poor fit for the nature of JavaScript! Using
await
/async
might help alleviate this, but then we're introducing more confusing keywords.Help!
The text was updated successfully, but these errors were encountered: