Coroutine与事件驱动编程

关于维基百科中的示例: http://en.wikipedia.org/wiki/Coroutine
var q := new queue

coroutine produce
    loop
        while q is not full
            create some new items
            add the items to q
        yield to consume

coroutine consume
    loop
        while q is not empty
            remove some items from q
            use the items
        yield
我只是想知道基于传统事件的方法可以处理这种使用模式,为什么需要使用协同程序?     
已邀请:
我认为这是“传统”的协同程序,事件是“现代的”。但是,他们也有不同的目的; AFAIK,协程可以指定传输控制的位置(如方法调用)或用于时间共享,而事件是松散耦合的通信(即,在分层架构中“向上”通信)。 如果您对这些事情感兴趣,请务必阅读Eric Lippert关于延续传递风格的博客系列(2010年10月)。有一篇帖子名为“关于协同作用的Musings”。     

要回复问题请先登录注册