Skip to content

Commit

Permalink
add timestamps to tick_tock
Browse files Browse the repository at this point in the history
  • Loading branch information
zh217 committed Sep 8, 2018
1 parent e6c5b48 commit 1765305
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions aiochan/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,8 @@ def tick_tock(seconds, start_at=None, loop=None):
"""
Returns a channel that gives out values every `seconds`.
The channel contains numbers from 1, counting how many ticks have been passed.
The channel contains tuples, in which the first elements are numbers from 1, counting how many ticks have been
passed, and the second elements are the times at which the elements are generated.
:param start_at: if `None`, the first tick occurs `seconds` later. If given, the first tick occurs at the given time
(in float).
Expand All @@ -1142,7 +1143,7 @@ def tick_tock(seconds, start_at=None, loop=None):
def tick():
nonlocal ct
ct += 1
if c.put_nowait(ct, immediate_only=False) is not False:
if c.put_nowait((ct, loop.time()), immediate_only=False) is not False:
loop.call_at(start_time + seconds * ct, tick)

loop.call_at(start_time, tick)
Expand Down
2 changes: 1 addition & 1 deletion aiochan/test/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ async def test_drop_while():
@pytest.mark.asyncio
async def test_tick_tock():
c = tick_tock(0.001)
assert list(range(1, 11)) == await c.collect(10)
assert list(range(1, 11)) == [i for i, _ in await c.collect(10)]
c.close()
await asyncio.sleep(0.01)

Expand Down

0 comments on commit 1765305

Please sign in to comment.