DelayQueue implementation

My team at work is in the process of converting some code over to Swift concurrency, and we find ourselves needing a replacement for our RetryQueue, which leverages Timers and a PriorityQueue to retry work items after a specified delay. Something like DelayQueue from Java seems ideal for this use case. Does anyone have thoughts on how to build something like that in Swift?

My current thinking is to use AsyncStream to pass work items ready to be retried to consumers and Task.sleep to delay. I'm getting stuck trying to understand the best way to reset the logic when a new item gets enqueued.

1 Like

This would probably not be the best fit for the swift-collections package, because it is mostly for publishing classic synchronous data structure implementations -- which is already a quite large domain to cover. Adding concurrent/async data structures would dramatically increase the scope of the package (and reduce its focus).

On the other hand, I think there would be room for one or more new "Standard Library-adjacent" packages dedicated to this general topic, though. Most of that work is currently blocked on properly modeling synchronization primitives in Swift, though.