Mirror: 馃帺 A tiny but capable push & pull stream library for TypeScript and Flow
at v4.0.5 902 B view raw
1open Wonka_types; 2 3let talkbackPlaceholder = (. _: talkbackT) => (); 4 5type trampolineT = { 6 mutable ended: bool, 7 mutable looping: bool, 8 mutable pull: bool, 9}; 10 11let makeTrampoline = (sink: sinkT('a), f: (. unit) => option('a)) => { 12 let state: trampolineT = {ended: false, looping: false, pull: false}; 13 14 sink(. 15 Start( 16 (. signal) => 17 switch (signal, state.looping) { 18 | (Pull, false) => 19 state.pull = true; 20 state.looping = true; 21 22 while (state.pull && !state.ended) { 23 switch (f(.)) { 24 | Some(x) => 25 state.pull = false; 26 sink(. Push(x)); 27 | None => 28 state.ended = true; 29 sink(. End); 30 }; 31 }; 32 33 state.looping = false; 34 | (Pull, true) => state.pull = true 35 | (Close, _) => state.ended = true 36 }, 37 ), 38 ); 39};