-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First implementation of the new consumer API
- Added Consumer class to handle messages consumsion - Added consumer queues in channels to wire the Consumer with the Channel - Fixed all test - Need test of stop of consumsion, documentation and update of examples
- Loading branch information
Sergio Medina Toledo
committed
Oct 27, 2016
1 parent
2142244
commit 6ac5bd2
Showing
8 changed files
with
159 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
import asyncio | ||
|
||
import sys | ||
|
||
PY35 = sys.version_info >= (3, 5) | ||
|
||
|
||
class Consumer: | ||
def __init__(self, queue: asyncio.Queue, consumer_tag): | ||
self.queue = queue | ||
self.tag = consumer_tag | ||
self.message = None | ||
|
||
if PY35: | ||
async def __aiter__(self): | ||
return self | ||
|
||
async def __anext__(self): | ||
return self.fetch_message() | ||
|
||
@asyncio.coroutine | ||
def fetch_message(self): | ||
|
||
self.message = yield from self.queue.get() | ||
if self.message: | ||
return self.message | ||
else: | ||
raise StopIteration() | ||
|
||
def get_message(self): | ||
return self.message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.