How can you do Co-routines using C#?

Posted by WeNeedAnswers on Stack Overflow See other posts from Stack Overflow or by WeNeedAnswers
Published on 2010-03-22T15:07:51Z Indexed on 2010/03/22 15:11 UTC
Read the original article Hit count: 497

Filed under:
|

In python the yield keyword can be used in both push and pull contexts, I know how to do the pull context in c# but how would I achieve the push. I post the code I am trying to replicate in c# from python:

def coroutine(func):
def start(*args,**kwargs):
cr = func(*args,**kwargs)
cr.next()
return cr
return start

@coroutine
def grep(pattern):
print "Looking for %s" % pattern
try:
while True:
line = (yield)
if pattern in line:
print line,
except GeneratorExit:
print "Going away. Goodbye"

© Stack Overflow or respective owner

Related posts about python

Related posts about c#