Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

Resolves #4117.

@jdegoes
Copy link
Member

jdegoes commented Aug 20, 2020

I think we have to avoid this behavior on Scala.js, or else it becomes impossible to run anything asynchronously, right? At least, assuming we end up with setImmediate for our execution context.

Some callback code in JS has to be run synchronously: e.g. when you handle a mouse or keyboard event.

@adamgfraser
Copy link
Contributor Author

Yes, I think that is a fairly straightforward change on Scala.js. The fact that all the test suites fail with this change on the JVM is somewhat concerning.

@adamgfraser adamgfraser requested a review from jdegoes August 20, 2020 17:32
@adamgfraser
Copy link
Contributor Author

The issue was that unsafeRunSync was defined in terms of unsafeRunAsync. unsafeRunSync is relatively safe for small effects if the effect is run on the same thread because then the OneShot will be set by the time get is called so there will be no blocking. But if we introduce an asynchronous step at the beginning every time the current thread immediately proceeds to evaluate OneShot#get blocking and potentially starving the ZIO thread pool if the thread that was evaluating unsafeRunSync was one of the ones from the ZIO thread pool.

@tusharmath
Copy link
Contributor

Just a thought: Why not use Promise.then() in Scala.js to schedule things instead of setImmediate.

That will actually guarantee that the callback scheduled will execute as soon as the current call stack is completed.

@adamgfraser
Copy link
Contributor Author

@tusharmath I think we need to do a subsequent PR where we look at all the options for how submitting an effect to the Executor on Scala.js should be interpreted but that should definitely be one of them.

@jdegoes jdegoes merged commit 26cff65 into zio:master Aug 25, 2020
@adamgfraser adamgfraser deleted the 4117 branch August 25, 2020 16:41
context.runAsync(k)

fiberId => unsafeRun(context.interruptAs(fiberId))
lazy val curZIO = if (Platform.isJS) zio else ZIO.yieldNow *> zio
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't the situation of JavaScript here similar to that of Native?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the situation is on Native here. At this point we have no tests for Native and there is an ongoing effort to get those working with associated changes so my overall point of view is we address Native specific issues as part of that but could definitely flip this to only yield on the JVM.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unsafeExecute evaluates on the current thread pool

4 participants