meteor / promise

ES6 Promise polyfill with Fiber support
MIT License
63 stars 15 forks source link

Don't force non-fiber-dependent code into fibers #9

Open kentonv opened 8 years ago

kentonv commented 8 years ago

We have a lot of code in Sandstorm that uses Promises with no need for fibers. When we need to interact with Meteor, we explicitly switch into a fiber to do it.

This package appears to be monkey-patching the built-in Promise to run all continuations in fibers. Unfortunately, Fibers are not free and this code can hurt performance quite a bit -- especially considering https://github.com/meteor/meteor/issues/7747 but even if that is fixed.

It would have been best if this package had introduced a new method -- say, .thenFiber() -- rather than monkey-patching .then() for the whole process. Unfortunately, I imagine it's too late to do that now.

I think an acceptable compromise would be: if .then() is not called from a fiber, then the callbacks it provides should not be called from a fiber. This would make it relatively easy for us to opt-out of fibers in our non-Meteor parts, but probably wouldn't break Meteor code.