Commit a1233a4a authored by Jason Madden's avatar Jason Madden

More shared code in imap

parent adb7e148
...@@ -203,6 +203,7 @@ class Group(object): ...@@ -203,6 +203,7 @@ class Group(object):
def wait_available(self): def wait_available(self):
pass pass
class _IMapBase(Greenlet): class _IMapBase(Greenlet):
_zipped = False _zipped = False
...@@ -230,16 +231,6 @@ class _IMapBase(Greenlet): ...@@ -230,16 +231,6 @@ class _IMapBase(Greenlet):
g.rawlink(self._on_result) g.rawlink(self._on_result)
return g return g
class IMapUnordered(_IMapBase):
def next(self):
value = self.queue.get()
if isinstance(value, Failure):
raise value.exc
return value
__next__ = next
def _run(self): def _run(self):
try: try:
func = self.func func = self.func
...@@ -250,6 +241,16 @@ class IMapUnordered(_IMapBase): ...@@ -250,6 +241,16 @@ class IMapUnordered(_IMapBase):
self.__dict__.pop('func', None) self.__dict__.pop('func', None)
self.__dict__.pop('iterable', None) self.__dict__.pop('iterable', None)
class IMapUnordered(_IMapBase):
def next(self):
value = self.queue.get()
if isinstance(value, Failure):
raise value.exc
return value
__next__ = next
def _on_result(self, greenlet): def _on_result(self, greenlet):
self.count -= 1 self.count -= 1
if greenlet.successful(): if greenlet.successful():
...@@ -280,7 +281,6 @@ class IMap(_IMapBase): ...@@ -280,7 +281,6 @@ class IMap(_IMapBase):
self.maxindex = -1 self.maxindex = -1
_IMapBase.__init__(self, func, iterable, spawn, _zipped) _IMapBase.__init__(self, func, iterable, spawn, _zipped)
def next(self): def next(self):
while True: while True:
if self.waiting and self.waiting[0][0] <= self.index: if self.waiting and self.waiting[0][0] <= self.index:
...@@ -296,17 +296,11 @@ class IMap(_IMapBase): ...@@ -296,17 +296,11 @@ class IMap(_IMapBase):
return value return value
__next__ = next __next__ = next
def _run(self): def _ispawn(self, func, item):
try: g = _IMapBase._ispawn(self, func, item)
func = self.func
for item in self.iterable:
g = self._ispawn(func, item)
self.maxindex += 1 self.maxindex += 1
g.index = self.maxindex g.index = self.maxindex
finally: return g
self.__dict__.pop('spawn', None)
self.__dict__.pop('func', None)
self.__dict__.pop('iterable', None)
def _on_result(self, greenlet): def _on_result(self, greenlet):
self.count -= 1 self.count -= 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment