-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[v5.4.0] Add support for commands and startups which return Promises (then-ables) #9103
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
base: master
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for tiddlywiki-previews ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Confirmed: Arlen22 has already signed the Contributor License Agreement (see contributing.md) |
📊 Build Size Comparison:
|
Branch | Size |
---|---|
Base (master) | 2528.1 KB |
PR | 2528.5 KB |
Diff: ⬆️ Increase: +0.4 KB
Good stuff, thank you @Arlen22. I note that at this point this PR results in a modest 0.4KB increase in the size of empty.html. Is there any scope to realise savings elsewhere through adopting the new capability? |
Not if I want it to be ES5-compatible. But once we moved to ES 2017 then I absolutely think so. Not sure if ES5 compatibility is important or not this late in the game. |
Hi @Arlen22 I've just updated the v5.4.0 planning ticket to specify that we are targetting ES 2017 for v5.4.0. |
@Jermolene, I think that's the wrong link. |
Ok, disregard the ES5 part, this is ready for v5.4.0 and ES2017 |
Per #9065 (comment), Promises and async functions are now supported by TiddlyWiki, so here's the code that I've always wanted to add to the commander and startup routines to support promises.
This preserves existing behavior, so if you just add the async keyword in front of your startup function or command.execute function, it will behave exactly like a sync function. This does not change the execution semantics at all, so throws are still uncaught, setting
synchronous = false
will still require you to call the callback function, and the return value of commands is still used as an error.The only difference is that if you return a Promise or use the async keyword, the promise will be awaited and the resolved value becomes the return value of the function.
Technically it's just looking for a then-able, not an
instanceof Promise
.This is what the JavaScript spec actually does with the
await
keyword as well.This preserves existing behavior unless: