Commit 999212d
authored
feat(delay): add Delay queue (#61)
A Queue[T comparable] implementation where each element becomes
dequeuable at a deadline computed by a caller-supplied function at
Offer time.
API:
- NewDelay(elems, deadlineFunc, opts...) — matches NewPriority's
constructor-time func pattern.
- Queue[T] surface plus GetWait.
- MarshalJSON serialises in deadline order.
Impl:
- Min-heap by deadline, written directly on []delayed[T] rather than
via container/heap. The container/heap Push/Pop signatures require
boxing each element into `any`, which pprof showed as the dominant
allocation source (>75% of allocations, ~50% of CPU spent in GC).
Typed push/pop/up/down keeps Get+Offer steady-state at 0 allocs.
- GetWait uses sync.Cond + time.AfterFunc so "head is due" and "state
changed" compose under a single Wait, matching the cond-var idiom
used by Blocking.
- Peek returns the head regardless of whether its deadline has passed
(matches java.util.concurrent.DelayQueue.peek).
- Panics on nil deadlineFunc or negative capacity, consistent with
NewPriority.
README: new Delay Queue section with usage example; benchmark table
extended.1 parent 5bacf9d commit 999212d
4 files changed
Lines changed: 955 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
267 | 268 | | |
268 | 269 | | |
269 | 270 | | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
270 | 315 | | |
271 | 316 | | |
272 | 317 | | |
| |||
284 | 329 | | |
285 | 330 | | |
286 | 331 | | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
287 | 335 | | |
0 commit comments