diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-09-23 03:23:40 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-09-23 03:23:40 -0300 |
| commit | b4422c99e10a8daee452b22aea84cb1f68ae54bc (patch) | |
| tree | 1f2ac50f4c536b8da83fca654cb3a6dee86a9975 /lib/kernel/Generator.ml | |
| parent | f88aeff9f7a673e945484a31fbcaed647bb3d2fa (diff) | |
| download | RNT-b4422c99e10a8daee452b22aea84cb1f68ae54bc.tar.gz RNT-b4422c99e10a8daee452b22aea84cb1f68ae54bc.zip | |
refactor ephemeral and subs relations
Diffstat (limited to 'lib/kernel/Generator.ml')
| -rw-r--r-- | lib/kernel/Generator.ml | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/lib/kernel/Generator.ml b/lib/kernel/Generator.ml index f9aafb0..b8f4962 100644 --- a/lib/kernel/Generator.ml +++ b/lib/kernel/Generator.ml @@ -10,20 +10,25 @@ let start produce = let resume k = Effect.Deep.continue k () -class producer_cursor produce on_release = +class producer_cursor produce finally = object (self) inherit Lifecycle.null inherit Identity.of_id val mutable state : [`Fresh | `Live of (unit, step) Effect.Deep.continuation | `Done] = `Fresh method protocols : Protocols.Handle.protocol list = Protocols.[Cursor.make self] + + method private finish = + state <- `Done; + Option.iter (fun f -> f ()) finally + method private step : (Concepts.Tuple.t option, Concepts.Condition.condition) result = let settle = function | Element (tuple, k) -> state <- `Live k; Ok (Some tuple) | Finished r -> - state <- `Done; + self#finish; Result.map (fun () -> None) r in match state with @@ -45,12 +50,8 @@ class producer_cursor produce on_release = Ok Protocols.Cursor.{tuples= BatFingerTree.empty; exhausted= (state = `Done)} else fill 0 BatFingerTree.empty - method! release = - (match state with - | `Fresh | `Live _ -> Option.iter (fun f -> f ()) on_release - | `Done -> ()); - state <- `Done + method! release = match state with `Fresh | `Live _ -> self#finish | `Done -> () end -let cursor_of ?on_release produce = - new producer_cursor produce on_release |> Protocols.Handle.make +let cursor_of ?finally produce = + new producer_cursor produce finally |> Protocols.Handle.make |
