Use AsyncTimerSequence from swift-async-algorithms#986
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.
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.
Note that we also don't need the cancel then -- just run it once :)
| if let timerTask = self.flushTimerTasks.removeValue(forKey: timerTaskKey) { | ||
| timerTask.cancel() | ||
| } | ||
| break |
There was a problem hiding this comment.
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.
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.
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.
Thanks for the warning cleanups while here 👍
Resolves #958