-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from swipely/dev/upgrade-csp
Upgrade js-csp; add API to run cursor while loop
- Loading branch information
Showing
5 changed files
with
75 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { go, poll, take } from 'js-csp'; | ||
|
||
function runUpdateLoop(cursorCh, handleUpdate) { | ||
const initialCursor = poll(cursorCh); | ||
|
||
go(function* () { | ||
let cursor; | ||
|
||
while ((cursor = yield take(cursorCh))) { | ||
// Allow the callback to exit the while loop | ||
if (handleUpdate(cursor) === false) { | ||
return; | ||
} | ||
} | ||
}); | ||
|
||
return initialCursor; | ||
} | ||
|
||
export default runUpdateLoop; |
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