Fork me on GitHub
#core-async
<
2018-02-16
>
benzap03:02:47

Hello, I was wondering if there is a way to make the clojurescript core.async work in a way such that it will continue to run it's event-loop while a given web application isn't the currently open tab in browsers like chrome

benzap03:02:29

From what I can tell, it's using requestAnimationFrame, which doesn't fire if the window isn't open. Is there a way to force it to fallback to use timeouts, or somehow have it fallback only when it isn't open?

benzap03:02:04

or rather, it looks like it might be a google closure problem with goog.async :S

pyr15:02:13

@tbaldridge @alexmiller you're right, I'm not verbalizing this correctly

pyr15:02:37

It's one way, but there are two ends to the tube

pyr15:02:44

and I was confused about which end close! closed

pyr15:02:06

as it turns out draining fixes the issue we were running into

pyr15:02:20

i'll run over to JIRA now to amend what I wrote there

noisesmith18:02:57

@benzap wouldn’t it be the browser itself controlling whether timeOut events actually fire in nonfocused tabs?

noisesmith18:02:14

or can you verify normal timeOut works in background tabs but not core.async?

benzap19:02:44

If I do a small test in the console, it appears to fire the timeout after the specified time, even when I unfocus the tab

benzap19:02:41

I was looking over how core.async is implemented, it appears to be using setImmediate

benzap19:02:52

I'll see if it's consistent between chrome, firefox, and ie

benzap19:02:33

haha, this is so strnage

benzap19:02:56

so I set a timer for 10s using core.async logic, and opened a different tab in firefox

benzap19:02:11

the timer went off after ~17 seconds

benzap19:02:43

chrome and ie-edge don't go off whatsoever until I open up the tab again

benzap19:02:35

it's possible that firefox doesn't have setImmediate, so it falls back to some sort of a timeout when compared to the other two browsers, but i'm not sure at this point

benzap19:02:43

If I could somehow figure out a way to check when the current javascript environment is closed, I could switch the core.async event loop over to a setTimeout fallback

benzap21:02:32

Alright, so I messed around with it, and it turns out that core.async does run while the window is not focused, but at reduced tick rate

benzap21:02:12

However, the ui event loop doesn't appear to work. There is no re-render of a react dom, which is why certain functionality that I want to work, won't. I'm assuming the react re-render is done via requestAnimationFrame

hiredman22:02:36

that seems sort of like something I might think twice about trying to circumvent

hiredman22:02:26

as a user I don't want a page that I am not looking that doing anything, which is, as I understand it, largely the reason some browsers have reduced what they can do

benzap22:02:24

The web app i'm writing is a timer, without the changes it would never play an alarm when the timer has finished.

hiredman22:02:05

I guess my question there would be, do you think it is a good design to have playing audio depend on your rendering layer?

benzap22:02:22

haha, not at all