question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Coroutine yield handler

See original GitHub issue

I’m now close to solving the problems with CLS and coroutines - see https://github.com/sequelize/sequelize/issues/6116#issuecomment-232377612

Therefore the time of coroutines is almost upon us! Next question is how to implement.

Method of wrapping ES6 class methods is being covered in https://github.com/sequelize/sequelize/issues/6116.

But also there’s the question of yield handlers.

Bluebird.coroutine() out of the box only supports yielding a Promise i.e. yield promise. But co adds other options like yielding an array of promises for parallel execution (yield [promise, promise, promise] as sugar for yield Promise.all( [promise, promise, promise] )).

I’ve been using co for a long time and find these extra features invaluable. But I think we’d need to stick with Bluebird.coroutine() to maintain CLS support, performance, and nice stack traces. Bluebird.coroutine.addYieldHandler() can then be used to implement some sugar.

There are some projects out there like bluebird-co that do this, but I think it’s important we maintain the principle that Sequelize.Promise is an independent instance of Bluebird and that any yield handler is added only toSequelize.Promise, and not to the global Bluebird instance - as that could cause unexpected behavior in apps/other modules. And I’m not sure if bluebird-co supports that.

Questions:

  1. Do others agree with me that the sugar is desirable?
  2. Do we agree about the principles I outline above?
  3. Any ideas as how to implement the yield handler?

@mickhansen @janmeier @sushantdhiman @felixfbecker

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:21 (21 by maintainers)

github_iconTop GitHub Comments

1reaction
sushantdhimancommented, Jul 15, 2016

I did used addYieldHandler(bluebird_co.toPromise); thats why it didn’t rejected, So without any yield handler it did reject. You guys are right 🏁

0reactions
overlookmotelcommented, Sep 7, 2016

(with apologies to @sushantdhiman - it seems you’re outvoted on yield handlers, though it’d also be difficult to achieve without adding a dependency, which you’re also against)

Read more comments on GitHub >

github_iconTop Results From Across the Web

yield - Kotlin
Yields the thread (or thread pool) of the current coroutine dispatcher to other coroutines on the same dispatcher to run if possible.
Read more >
Promise.coroutine.addYieldHandler - Bluebird JS
Yield handlers are called when you yield something that is not supported by default. The first yield handler to return a promise or...
Read more >
Coroutines - Unity - Manual
In Unity, a coroutine is a method that can pause execution and return ... By default, Unity resumes a coroutine on the frame...
Read more >
Coroutine in Python - GeeksforGeeks
Coroutines are generalizations of subroutines. They are used for cooperative multitasking where a process voluntarily yield (give away) ...
Read more >
Tornado coroutine yield from another coroutine incrementally
You must use Python 3.6 native coroutines for this to work. This was the first version of Python that supported both yield and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found