Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- console.clear()
- async function main() {
- const delay = time=>new Promise(resolve => setTimeout(()=>resolve(), time))
- const functionInvocationsObservable = new Rx.Subject()
- .bufferTime(/* buffer time*/ 500, /* restart buffer, -1 means never */ -1, /* maxBufferSize*/ 3)
- .filter(x => x.length > 0)
- // .subscribe(console.log)
- const batchify = func => {
- functionInvocationsObservable.subscribe(x => {
- console.log(x)
- func(x)
- })
- return function() {
- functionInvocationsObservable.next(...arguments)
- }
- }
- const foo = batchify(x=>x * 2)
- for (let i = 0; i <= 10; i++) {
- await delay(100)
- console.info(`invoked with: ${i}`)
- foo(i)
- }
- await delay(100)
- console.info(`invoked with: ${28}`)
- foo(28)
- foo(30)
- foo(42)
- }
- main()
Add Comment
Please, Sign In to add comment