From 4fc8d229ebb35ec4e05ad2612e1e473950d5eb52 Mon Sep 17 00:00:00 2001 From: James Hillyerd Date: Sun, 5 Apr 2020 17:27:22 -0700 Subject: [PATCH] ui: impl Timer.schedule function --- ui/src/Layout.elm | 6 +++--- ui/src/Timer.elm | 13 ++++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/ui/src/Layout.elm b/ui/src/Layout.elm index 42d3ac3..e4ff701 100644 --- a/ui/src/Layout.elm +++ b/ui/src/Layout.elm @@ -93,7 +93,7 @@ type Msg | OpenMailbox | RecentMenuMouseOver | RecentMenuMouseOut - | RecentMenuTimeout Timer () + | RecentMenuTimeout Timer | RecentMenuToggled @@ -155,10 +155,10 @@ update msg model session = | recentMenuTimer = newTimer } , session - , Process.sleep 400 |> Task.perform (RecentMenuTimeout newTimer >> model.mapMsg) + , Timer.schedule (RecentMenuTimeout >> model.mapMsg) newTimer 400 ) - RecentMenuTimeout timer _ -> + RecentMenuTimeout timer -> if timer == model.recentMenuTimer then ( { model | recentMenuVisible = False diff --git a/ui/src/Timer.elm b/ui/src/Timer.elm index 4fa640a..fc82d44 100644 --- a/ui/src/Timer.elm +++ b/ui/src/Timer.elm @@ -1,9 +1,11 @@ -module Timer exposing (Timer, cancel, empty, replace) +module Timer exposing (Timer, cancel, empty, replace, schedule) + +import Process +import Task + {-| Implements an identity to track an asynchronous timer. -} - - type Timer = Empty | Idle Int @@ -15,6 +17,11 @@ empty = Empty +schedule : (Timer -> msg) -> Timer -> Float -> Cmd msg +schedule message timer millis = + Task.perform (always (message timer)) (Process.sleep millis) + + {-| Replaces the provided timer with a newly created one. -} replace : Timer -> Timer