-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into remove_termbase_modules
- Loading branch information
Showing
6 changed files
with
94 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
open Core; | ||
open Bonsai; | ||
open Bonsai.Let_syntax; | ||
|
||
module Alarm = { | ||
module Action = { | ||
[@deriving sexp] | ||
type t = | ||
| SetAlarm(Time_ns.Alternate_sexp.t) | ||
| SnoozeAlarm(Time_ns.Alternate_sexp.t) | ||
| UnsetAlarm; | ||
}; | ||
|
||
let alarm = | ||
state_machine0( | ||
(module Time_ns.Alternate_sexp), | ||
(module Action), | ||
~default_model=Time_ns.max_value_representable, | ||
~apply_action=(~inject as _, ~schedule_event as _, model, action) => { | ||
switch (action) { | ||
| SetAlarm(time) => time | ||
| SnoozeAlarm(time) => Time_ns.max(time, model) | ||
| UnsetAlarm => Time_ns.max_value_representable | ||
} | ||
}); | ||
|
||
let listen = (alarm, ~event) => { | ||
let%sub before_or_after = Clock.at(alarm |> Value.map(~f=fst)); | ||
Edge.on_change( | ||
(module Clock.Before_or_after), | ||
before_or_after, | ||
~callback={ | ||
open Clock.Before_or_after; | ||
let%map (_, inject) = alarm | ||
and event = event; | ||
fun | ||
| After => Effect.Many([inject(Action.UnsetAlarm), event]) | ||
| Before => Effect.Ignore; | ||
}, | ||
); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters