Skip to content

Feature request: Effect.Process.spawn/kill + actual sleep delay simulation #20

@CharlonTank

Description

@CharlonTank

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:

  1. I remove it from my scheduledTasks dict
  2. I create a new Effect.Process.sleep command
  3. 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, ignore

This works but creates noisy test output with many phantom messages.

Questions

  1. Is implementing actual sleep delays on the roadmap?
  2. Would spawn/kill make sense once delays work?
  3. Happy to help with test cases or contributions if useful!

Thanks for the amazing library! 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions