-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Context
I'm building a Lamdera app with scheduled tasks (rent creation on specific dates, ticket reminders after 3 days of inactivity). These tasks can be cancelled/rescheduled.
Current Behavior
1. Sleep delays are ignored in tests
In Effect/Test.elm (lines 3857-3859):
SleepTask _ function ->
-- TODO: Implement actual delays in tasks
runTask maybeClientId state (function ())All sleeps execute immediately when the command is created, ignoring the duration.
2. No way to cancel in-flight sleeps
Effect.Process only exposes sleep, not spawn, kill, or Id from the standard Process module.
When I reschedule a task:
- I remove it from my
scheduledTasksdict - I create a new
Effect.Process.sleepcommand - But the previous sleep is already "in flight" and will still fire
This creates many phantom messages that I have to filter out in my handler.
Proposed Solution
Phase 1: Implement actual sleep delays
Track pending sleep tasks with their scheduled execution time. When fastForward or wait advances time past a scheduled sleep, execute it.
Phase 2: Add spawn/kill support
module Effect.Process exposing (sleep, spawn, kill, Id)
spawn : Task x a -> Task y Id
kill : Id -> Task x ()This would allow properly cancelling scheduled tasks.
Workaround
Currently I check task validity when ExecuteScheduledTask fires:
executeTask taskId expectedTime model =
case Dict.get taskId model.scheduledTasks of
Just entry ->
if entry.scheduledAt == expectedTime then
Just ( entry, { model | scheduledTasks = Dict.remove taskId model.scheduledTasks } )
else
Nothing -- Task was rescheduled, ignore
Nothing ->
Nothing -- Task was cancelled, ignoreThis works but creates noisy test output with many phantom messages.
Questions
- Is implementing actual sleep delays on the roadmap?
- Would
spawn/killmake sense once delays work? - Happy to help with test cases or contributions if useful!
Thanks for the amazing library! 🙏