andrewMacmurray/elm-delay/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

Delay

Utilities to delay updates after a set period of time

Delay one message

after : Float -> msg -> Cmd msg

Delays an update (with a message) by a given number of milliseconds

-- triggers DelayedMsg after 500ms
after 500 DelayedMsg

Delay a sequence of messages

start : (List ( Float, msg ) -> msg) -> List ( Float, msg ) -> Cmd msg

Starts a sequence of messages given the SequenceMsg and a list of messages to be sent

type Msg
    = FirstMsg
    | SecondMsg
    | ThirdMsg
    | Sequence (List ( Float, Msg ))


-- triggers each Msg one after the other with a 500ms delay
start Sequence
  [ (500, FirstMsg)
  , (500, SecondMsg)
  , (500, ThirdMsg)
  ]
startIf : Bool -> (List ( Float, msg ) -> msg) -> List ( Float, msg ) -> Cmd msg

Starts a sequence if a predicate value is True. This is helpful if you'd like to start the sequence only if your model is in a particular shape

startIf (not model.updating) Sequence
  [ (500, FirstMsg)
  , (500, SecondMsg)
  , (500, ThirdMsg)
  ]
(List ( Float, msg ) -> msg)
-> List ( Float, msg )
-> (msg -> model -> ( model, Cmd msg ))
-> model
-> ( model, Cmd msg )

Calls update with each message and a delay until finished.

-- recursively calls update until all Msgs have been processed
Sequence msgs ->
  handleSequence Sequence update model