3 ms·
Seems you have misunderstood how it works. https://github.com/visionmedia/co/blob/master/index.js https://github.com/visionmedia/co/blob/master/index.js Typica
by jeswin 13y ago
Seems you have misunderstood how it works. https://github.com/visionmedia/co/blob/master/index.js https://github.com/visionmedia/co/blob/master/index.js
Typically in apps using 'co', functions will return generators, not promises. Promises were probably added because of all the existing code out there.
Here is a file from my ongoing project, should explain how generators are being used. See getPosts() or addPost() https://github.com/jeswin/fora/blob/master/server/src/models/forum.coffee https://github.com/jeswin/fora/blob/master/server/src/models...
[Edit: Just read your earlier (Gr.GP) comment. Might want to avoid the unnecessary snark, especially when there's a chance you might be wrong.]
- masklinn 13y ago> Seems you have misunderstood how it works. https://github.com/visionmedia/co/blob/master/index.js https://github.com/visionmedia/co/blob/master/index.js No. > Typically in apps using 'co', functions will return generators, not promises. Promises were probably added because of all the existing code out there. Again, generators in and of themselves don't do anything (for async code). Something needs to be generated/yielded, and that thing is the reification of an asynchronous operation. Such as a promise[0]. Generators and promises fulfil different roles, generators are used as imperative "sugar" for chaining promises. The generators you yield will ultimately resolve into a series of async operations (promises or "thunks"), yielding a generator is convenience (not very useful convenience either, since `yield*` exists the ability to yield generators just complexifies the driver) [0] and in the case of co a "thunk"[1], because node