co icon indicating copy to clipboard operation
co copied to clipboard

using co with node 0.10.x?

Open angelochen960 opened this issue 9 years ago • 3 comments

Hi,

co's home page says:

When using node 0.10.x and lower or browsers without generator support, you must use gnode and/or regenerator.

but when gnode an app, got:

ReferenceError: Promise is not defined
    at co (.../node_modules/co/index.js:50:14)

is there a way to polyfill this with Bluebird? or what is the version of co that can be used with node 0.10.x?

Thanks, A.C.

angelochen960 avatar Oct 10 '15 09:10 angelochen960

co@4+ requires a Promise implementation. For versions of node < 0.11 and for many older browsers, you should/must include your own Promise polyfill.

So yeah, you should do global.Promise = require('bluebird') or similar.

madbence avatar Oct 10 '15 09:10 madbence

Yes you can override global.Promise. Also, check out this current PR for "bring your own promise" in this repo. Kind of interesting (and related) https://github.com/tj/co/pull/244

joshbeam avatar Oct 11 '15 02:10 joshbeam

@madbence @joshbeam yeah, this will work for most of the cases, but we using co in test framework ava and including global polyfill will affect code under testing (if code relies on Promise object, but don't polyfill it in test).

floatdrop avatar Nov 01 '15 06:11 floatdrop