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

OR-5286 Timers:: Using DispatchQueue #143

Merged
merged 1 commit into from
Aug 17, 2023
Merged

OR-5286 Timers:: Using DispatchQueue #143

merged 1 commit into from
Aug 17, 2023

Conversation

crazymanish
Copy link
Owner

@crazymanish crazymanish commented Aug 17, 2023

Context

In this PR

  • Before the Dispatch framework was available, developers relied on RunLoop to asynchronously perform tasks and implement concurrency.
  • Timer (NSTimer in Objective-C) could be used to create repeating and non-repeating timers.
  • Then Dispatch arrived and with it, DispatchSourceTimer.

  • Using RunLoop
  • The main thread and any thread you create, preferably using the Thread class, can have its own RunLoop.
  • It is always better, to use the main RunLoop that runs the main thread of your application. RunLoop.main
  • RunLoop class is not thread-safe. means You should only call RunLoop methods for the run loop of the current thread.
  • RunLoop defines several methods which are relatively low-level, and the only one benefit that lets you create cancellable timers

  • Using the Timer class
  • Timer is the oldest timer that was available on the original Mac OS X, long before it was renamed “macOS.”
  • It has always been tricky to use because of its delegation pattern and tight relationship with RunLoop.
  • Combine brings a modern variant you can directly use as a publisher without all the setup boilerplate.

  • Using DispatchQueue
  • You can use a dispatch queue to generate timer events.
  • While the Dispatch framework has a DispatchTimerSource event source, Combine surprisingly doesn’t provide a timer interface to it. Instead, you’re going to use an alternative method to generate timer events in your queue.

@crazymanish crazymanish linked an issue Aug 17, 2023 that may be closed by this pull request
@crazymanish crazymanish merged commit 89899c3 into main Aug 17, 2023
@crazymanish crazymanish deleted the OR-5287 branch August 17, 2023 18:14
@crazymanish crazymanish mentioned this pull request Aug 17, 2023
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.

[w33(13august-19august)] Timers: Using DispatchQueue
1 participant