3 ms·
I don't normally use generators. I can't figure out how this syntax or functionality is in any way different from normal generators.
by ilaksh 3y ago
I don't normally use generators. I can't figure out how this syntax or functionality is in any way different from normal generators.
- steve_adams_86 3y agoI think it's unclear because the examples are simple enough that you could easily reproduce them with generators. I think the ball example (https://github.com/manuel/delimgen/blob/main/demo/balls.html https://github.com/manuel/delimgen/blob/main/demo/balls.html) is maybe the most helpful to look at. It provides an abstraction over the wrapped generator which allows you to inject events into the generator. You could do this with generators alone, but this syntax lets you write it more like synchronous code (and has the added benefit of not being "coloured" by async/await). The `run` method essentially allows you to pass of handling of a continuous process so you don't need to worry about the orchestration of concurrent tasks. In this case, ball is able to move itself around the document as soon as it's yielded, and the implementation details of that behaviour are totally hidden from where the event is injected. I'm still trying to wrap my head around how I'd use delimited continuation in more practical ways, so I might be misunderstanding quite badly. It seems to me that generators themselves are a form of continuation, and we often create delimited continuations when we implement programs with generators. In this case, the library essentially ties the loose ends by reifying the continuation as a function. In this case, the function is what provides the synchronous-like syntax as well.