Skip to content

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

@ivabra

Description

@ivabra

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() }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions