Skip to content

[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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Arlen22
Copy link
Member

@Arlen22 Arlen22 commented Jun 18, 2025

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.

const thenable = task.startup();
if(thenable && typeof thenable.then === "function") {
  thenable.then(executeNextTask);
} else {
  executeNextTask();
}

This preserves existing behavior unless:

  • in startup, you were returning junk promises that you expected to be ignored (but why?)
  • in commands, you were returning junk promises as your errors, which seems unlikely.

Copy link

netlify bot commented Jun 18, 2025

Deploy Preview for tiddlywiki-previews ready!

Name Link
🔨 Latest commit 2ce7098
🔍 Latest deploy log https://app.netlify.com/projects/tiddlywiki-previews/deploys/6852b24f02ea5b0008001315
😎 Deploy Preview https://deploy-preview-9103--tiddlywiki-previews.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link

Confirmed: Arlen22 has already signed the Contributor License Agreement (see contributing.md)

Copy link

📊 Build Size Comparison: empty.html

Branch Size
Base (master) 2528.1 KB
PR 2528.5 KB

Diff: ⬆️ Increase: +0.4 KB

@Arlen22 Arlen22 changed the title [v5.4.0] Add support for commands and startups which return promises Add support for commands and startups which return thenables (ES5 compatible) Jun 18, 2025
@Jermolene
Copy link
Member

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?

@Arlen22
Copy link
Member Author

Arlen22 commented Jun 18, 2025

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.

@Jermolene
Copy link
Member

Hi @Arlen22 I've just updated the v5.4.0 planning ticket to specify that we are targetting ES 2017 for v5.4.0.

@Arlen22 Arlen22 changed the title Add support for commands and startups which return thenables (ES5 compatible) [v5.4.0] Add support for commands and startups which return thenables Jun 18, 2025
@Arlen22
Copy link
Member Author

Arlen22 commented Jun 18, 2025

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.

@Arlen22
Copy link
Member Author

Arlen22 commented Jun 19, 2025

Ok, disregard the ES5 part, this is ready for v5.4.0 and ES2017

@Arlen22 Arlen22 mentioned this pull request Jun 19, 2025
@Arlen22 Arlen22 changed the title [v5.4.0] Add support for commands and startups which return thenables [v5.4.0] Add support for commands and startups which return Promises (then-ables) Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs feedback
Development

Successfully merging this pull request may close these issues.

3 participants