Closed dgilland closed 9 years ago
@lhorie Any thoughts on including this? If this is something you'd consider adding, I could take a stab at creating a pull request for it.
+1
I've worked around this by doing m.sync([ mRequestPromise ]).then( finalCallback )
which doesn't do the same thing, but is close enough in some cases.
@maranomynet your example is not correct, no need of m.sync
which is equivalent to Promise.all
in ES6.
The method finally()
is closer to something like myPromise.then(finalCallback, finalCallback); return myPromise;
.
This request is related to:
catch()
methodThe idea is to be fully compatible with ES6 API.
And also partially to
tap()
methodand other issues about promises
If Mithril had a Promise A+ compliant implementation (meaning fully async), it would be easyer to have a 100% ES6 compatible API, and thus use Browser ES6 Promise when available.
May be it's time to use an external polyfill for Promise like https://github.com/jakearchibald/es6-promise Browser support start to be quite good http://caniuse.com/#feat=promises
As I said, it's a workaround "which doesn't do the same thing". :-)
But it provides a quick way to execute a function after a m.request()
promise has been fully finished.
@lhorie It seems like this is again gone in v1.0?
@franzliedke It's because it now bundles a conditional polyfill for the ES6 native promise instead of exclusively using its own implementation like it did in 0.2. You may want to keep tabs on a related ES proposal, though.
Thoughts on adding a
finally()
method (or similarly named method) to the Promise API?My particular use-case is for clean-up code that needs to always run after an
m.request()
call regardless of anything that occurs further up the chain.Or is there already an idiomatic Mithril-way to do this?