Mirror: 🎩 A tiny but capable push & pull stream library for TypeScript and Flow
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remove strict end from delay operator (#56)

Delay does not have to pass `passesStrictEnd`,
since it's idempotent.

authored by

Phil Plückthun and committed by
GitHub
2b4d0fa2 7636c276

+6 -31
+6 -31
src/web/wonkaJs.re
··· 82 82 }) 83 83 ); 84 84 85 - type delayStateT = { 86 - mutable talkback: (. talkbackT) => unit, 87 - mutable active: int, 88 - mutable ended: bool, 89 - }; 90 - 91 85 [@genType] 92 86 let delay = (wait: int): operatorT('a, 'a) => 93 87 curry(source => 94 88 curry(sink => { 95 - let state: delayStateT = { 96 - talkback: Wonka_helpers.talkbackPlaceholder, 97 - active: 0, 98 - ended: false, 99 - }; 89 + let active = ref(0); 100 90 101 91 source((. signal) => 102 92 switch (signal) { 103 - | Start(tb) => state.talkback = tb 104 - | _ when !state.ended => 105 - state.active = state.active + 1; 93 + | Start(_) => sink(. signal) 94 + | _ => 95 + active := active^ + 1; 106 96 ignore( 107 97 Js.Global.setTimeout( 108 98 () => 109 - if (!state.ended || state.active !== 0) { 110 - state.active = state.active - 1; 99 + if (active^ !== 0) { 100 + active := active^ - 1; 111 101 sink(. signal); 112 102 }, 113 103 wait, 114 104 ), 115 105 ); 116 - | _ => () 117 106 } 118 - ); 119 - 120 - sink(. 121 - Start( 122 - (. signal) => 123 - switch (signal) { 124 - | Close when !state.ended => 125 - state.ended = true; 126 - state.talkback(. Close); 127 - | Close => () 128 - | Pull when !state.ended => state.talkback(. Pull) 129 - | Pull => () 130 - }, 131 - ), 132 107 ); 133 108 }) 134 109 );