Skip to content
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

fire() executes the closure in the current thread but not in the given dispatch queue #46

Open
ivabra opened this issue Jan 23, 2020 · 0 comments

Comments

@ivabra
Copy link

ivabra commented Jan 23, 2020

Description

Example code:

let timer = Repeater.every(.minutes(5), count: nil, tolerance: .seconds(1), queue: .global()) { 
 // Some long running operation... 
}
timer.fire()

Given the closure contains a relatively long-running operation, I use .global() queue for this purpose, but I want the closure to be run just after I schedule it because I need this operation to be run right now and not only after 5 mins.

Expected
The documentation doesn't tell me the aspects of force firing, so I think it is implied that the closure will be run in the queue that is given to the timer .

Actual
The closure is run in the current thread that may cause blocking of a blocking-sensible thread like the main.

Possible workaround
To fire the timer in a different queue.

DispatchQueue.global().async { timer.fire() }
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

No branches or pull requests

1 participant