Skip to content

feat: support later function in DeferedQueue#377

Open
albertcht wants to merge 6 commits into0.4from
feature/defered-queue-later
Open

feat: support later function in DeferedQueue#377
albertcht wants to merge 6 commits into0.4from
feature/defered-queue-later

Conversation

@albertcht
Copy link
Copy Markdown
Member

@albertcht albertcht commented Apr 28, 2026

Summary

Adds a later() method to DeferredQueue, allowing jobs to be scheduled for execution after a specified delay. This brings DeferredQueue to feature parity with DeferQueue and CoroutineQueue.

Changes

src/queue/src/DeferredQueue.php

  • Added an explicit constructor accepting ?bool $dispatchAfterCommit and ?Timer $timer (auto-instantiates Hypervel\Coordinator\Timer when none is injected)
  • Added later(DateInterval|DateTimeInterface|int $delay, ...) which delegates to Timer::after(), converting the delay to seconds via the inherited secondsUntil() helper, then calls deferJob() so the job still runs inside a deferred coroutine

tests/Queue/QueueDeferredQueueTest.php

  • testLaterSchedulesJobWithDelay — integer delay (5 s)
  • testLaterWithDateIntervalDateInterval delay (PT10S)
  • testLaterWithDateTimeDateTimeInterface delay via a Carbon instance (15 s ahead of frozen now)

All three tests mock Timer and assert that the correct SyncJob and payload reach the handler.

This PR has been merged in v0.3: #361

@albertcht albertcht requested a review from binaryfire April 28, 2026 09:55
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.

1 participant