Skip to content

Instantly share code, notes, and snippets.

@benlesh
Created August 23, 2017 01:06
Show Gist options
  • Save benlesh/6ea17efa795b1b40820c0fba004d4c84 to your computer and use it in GitHub Desktop.
Save benlesh/6ea17efa795b1b40820c0fba004d4c84 to your computer and use it in GitHub Desktop.
const click$ = Observable.fromEvent(button, 'clicks');
/**
* Waits for 10 clicks of the button
* then posts a timestamp of the tenth click to an endpoint
* using fetch
*/
async function doWork() {
await click$.take(10)
.forEach((_, i) => console.log(`click ${i + 1}`));
return await fetch(
'notify/tenclicks',
{ method: 'POST', body: Date.now() }
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment