New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interaction between setScheduler, longStackTraces, and async trampoline #650

Closed
metamatt opened this Issue Jun 12, 2015 · 6 comments

Comments

Projects
None yet
3 participants
@metamatt

metamatt commented Jun 12, 2015

I'm trying to use Bluebird alongside Angular 1.4 to replace Angular's $q (a la this suggestion).

I found that actions taken in a promise.then handler don't always get digested unless I trigger a digest cycle. I stepped around the Bluebird code a bit to see how the result of setScheduler was used, and it seems to be honored only if async._trampolineEnabled is true. And if I'm reading the code correctly, use of Promise.longStackTraces() in Chrome automatically disables the trampoline.

I'm new to this project so don't know the history with the trampoline, the Async abstraction, etc but I think I agree with the spin in the README.md on the sync build: don't use it (i.e. things are best with the trampoline enabled).

Also I noticed that calling Promise.enableTrampoline() implicitly re-enables the default scheduler, so if Promise.setScheduler() had previously been set, now it won't be.

Is it possible to make these features (long stack traces and setScheduler) work better together? (I see #542 but I don't know what the issue was there and the link is broken so it's hard to piece together the story starting now).

@petkaantonov

This comment has been minimized.

Show comment
Hide comment
@petkaantonov

petkaantonov Jun 12, 2015

Owner

It's basically not possible to implement invokeLater if trampoline is disabled. So when it is disabled, setTimeout is used as it's somewhat possible to reasonably emulate invokeLaterjust by using a huge timeout for invokeLater and small timeout for invoke. That's why it's not possible to use a custom scheduler when trampoline is disabled.

On the other hand, if trampoline is enabled, then Chrome DevTools won't show correct async stack trace (although the one logged on console is correct).

Owner

petkaantonov commented Jun 12, 2015

It's basically not possible to implement invokeLater if trampoline is disabled. So when it is disabled, setTimeout is used as it's somewhat possible to reasonably emulate invokeLaterjust by using a huge timeout for invokeLater and small timeout for invoke. That's why it's not possible to use a custom scheduler when trampoline is disabled.

On the other hand, if trampoline is enabled, then Chrome DevTools won't show correct async stack trace (although the one logged on console is correct).

@benjamingr

This comment has been minimized.

Show comment
Hide comment
@benjamingr

benjamingr Jun 12, 2015

Collaborator

@petkaantonov but can't bluebird call the scheduler for each function?

Do async stack traces work with $q?

I wonder if this should perhaps be an option in 3.0

Collaborator

benjamingr commented Jun 12, 2015

@petkaantonov but can't bluebird call the scheduler for each function?

Do async stack traces work with $q?

I wonder if this should perhaps be an option in 3.0

@petkaantonov

This comment has been minimized.

Show comment
Hide comment
@petkaantonov

petkaantonov Jun 12, 2015

Owner

@benjamingr no as I explained above

Owner

petkaantonov commented Jun 12, 2015

@benjamingr no as I explained above

@benjamingr

This comment has been minimized.

Show comment
Hide comment
@benjamingr

benjamingr Jun 12, 2015

Collaborator

Why? Wouldn't it just mean running whatever the scheduler is for each function instead of setTimeout?

Collaborator

benjamingr commented Jun 12, 2015

Why? Wouldn't it just mean running whatever the scheduler is for each function instead of setTimeout?

@petkaantonov

This comment has been minimized.

Show comment
Hide comment
@petkaantonov

petkaantonov Jun 12, 2015

Owner

we discussed offline and this could be done by implementing invoke like this

this.schedule(fn);

and invokeLater like this

this.schedule(function() {
    setTimeout(fn, 100);
});

when trampoline is disabled

Owner

petkaantonov commented Jun 12, 2015

we discussed offline and this could be done by implementing invoke like this

this.schedule(fn);

and invokeLater like this

this.schedule(function() {
    setTimeout(fn, 100);
});

when trampoline is disabled

@petkaantonov

This comment has been minimized.

Show comment
Hide comment
@petkaantonov

petkaantonov Jun 14, 2015

Owner

Fixed in 2.9.28

Owner

petkaantonov commented Jun 14, 2015

Fixed in 2.9.28

petkaantonov added a commit that referenced this issue Jun 14, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment