- Notifications
You must be signed in to change notification settings - Fork 79
Use AsyncTimerSequence from swift-async-algorithms #986
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
Conversation
Sources/DistributedActors/Cluster/Reception/OperationLogDistributedReceptionist.swift Outdated Show resolved Hide resolved
| await self.attemptToTakeForks() | ||
| self.becomeHungryTimerTask?.cancel() | ||
| break | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm okey those are just a "single" timers, so we can do these a bit simpler:
Task { try await Task.sleep(until: .now + .seconds(1), clock: .continuous) } There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that we also don't need the cancel then -- just run it once :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amended ef06ce6
| if let timerTask = self.flushTimerTasks.removeValue(forKey: timerTaskKey) { | ||
| timerTask.cancel() | ||
| } | ||
| break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's also a single timer, so we can do
self.flushTimerTasks[timerTaskKey] = Task { defer { self.flushTimerTasks.removeValue(forKey: timerTaskKey) } try await Task.sleep(until: .now + flushDelay, clock: .continuous) } hmm, the cancel seems un-necessary then as well; since we'll run to completion, but we do want to keep the removeValue 👍
| @available(*, deprecated, message: "Actor timers cannot participate in structured cancellation, and will be replaced with patterns using swift-async-algorithms (see Timer)") | ||
| public struct TimerKey: Hashable { | ||
| // TODO: replace timers with AsyncTimerSequence from swift-async-algorithms | ||
| internal struct _TimerKey: Hashable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great, thank you! the amount of un-necessary noise this caused was annoying
| /// _BehaviorTimers are bound to this objects lifecycle, i.e. when the actor owning this object is deallocated, | ||
| /// and the `ActorTimers` are deallocated as well, all timers associated with it are cancelled. | ||
| @available(*, deprecated, message: "Actor timers cannot participate in structured cancellation, and will be replaced with patterns using swift-async-algorithms (see Timer)") | ||
| public final class ActorTimers<Act: DistributedActor> where Act.ActorSystem == ClusterSystem { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bye bye 👋 If we ever get some other type similar to this it'll be based on tasks... we'll see if it ever comes back
| @swift-server-bot test this please |
| self.maxSeqNr = 0 | ||
| } | ||
| | ||
| @discardableResult |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the warning cleanups while here 👍
ktoso left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Resolves #958