Replies: 1 comment 1 reply
-
I've spent a few days thinking this through from the perspective of calling code. If the goal is to run async initialisers synchronously then the code you've posted will achieve that. I'd like to say it will require no modification but I'm unsure whether any JS implementation supports the async keyword without offering a global Promise. That brings me to a question. Given that Promise support was pronounced stable at NodeJS version 4 (i.e. ES6/ES2015) and @stamp targets ES2017 in master at the time of posting, which platforms are targeted that don't have global Promise available? Calling code gains no asynchronous benefits when asynchronous functions are executed synchronously using await. For now, I don't see any reason to hold back committing something like what you've posted. Like you wrote, it is low hanging fruit. It will give developers the flexibility to build stamps with asynchronous initialisers in preparation for the later performance benefit. As far as the performance benefit goes, I haven't experienced any issues in my code when a Promise is returned from an initialiser. Though it must be emphasised that there is a caveat for code cleanliness – calling code must use sync exclusively (including the code you posted) or async exclusively. There is no half way that is simple and sticking to this has kept me sane. For this reason, I would recommend that an alternative compose with full async support be available as a sub-export or another package. You did mention some potential problems with the full async support in the PR this RFC arose from and full async support is on the cards I reckon some sample code + tests might help confirm/deny their existence and any workarounds required. I'm utterly outside the scope of the stamp standard in this post and in my mind. I imagine some consideration might be necessary regarding asynchronous program flow. Even more complicated would be asynchronous composition hehe... but that's another RFC. Hope this is helpful. |
Beta Was this translation helpful? Give feedback.
-
Whilst this specification was being created the stampit v2 had a feature the spec didn't borrow. Stampit v2 could create objects even if its initialisers are async functions (return Promises). Stampit v3 comply to specs, so had to remove that feature.
Let's bring back async object creation. Why?
Proposal. Add this line:
Here is a sample implementation of the object creation bit:
As you can see, such implementation:
esm
,Babel
, native JS engines, everywhere!npmjs.com/~stamp
stamps.Beta Was this translation helpful? Give feedback.
All reactions