Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Chain = f => ({
- f,
- write: v => {
- f(() => console.log(v))
- return Chain(f)
- },
- wait: ms => Chain(next => setTimeout(() => f(next), ms))
- })
- let obj = Chain(next => next())
- // test case:
- // obj.write(4)
- // obj.wait(1000)
- // obj.write(4).write(3).write(2)
- // obj.wait(1000).wait(2000).write(4)
- // obj.wait(1000).write(1).wait(2000).write(2)
- // obj.write(1).wait(1000).write(2)
- // obj.wait(3000).write(1).write(2).wait(1000).write(3)
Add Comment
Please, Sign In to add comment