1
2
3
4 from __future__ import ( generators, with_statement )
5 from contextlib import contextmanager
6 import af
7
8 __all__ = [ 'server', 'pool' ]
9
12 self.s = af.socket.socket()
13 self.s.bind( ( host, port ) )
14 self.s.listen()
17 @af.task
19 res = yield self.s.accept()
20 yield af.result( res )
22
23 -class pool( object ):
25 self.tasks = []
26 self.spawn( *tasks )
27 - def spawn( self, *tasks ):
28 self.tasks.extend( af.spawn( t ) for t in tasks )
31 - def stop( self ): [ task.stop() for task in self.tasks ]
32
33 @contextmanager
35 try: yield x
36 finally: x.stop()
37