Add njs token bucket gist url

pause_feeds_on_sym_switch
Tyler Goodlet 2021-08-13 12:34:40 -04:00
parent c8e320849a
commit 2f5abaa47a
1 changed files with 7 additions and 1 deletions
piker/data

View File

@ -235,6 +235,8 @@ async def sample_and_broadcast(
try:
if tick_throttle:
# this is a send mem chan that likely
# pushes to the ``uniform_rate_send()`` below.
await stream.send(quote)
else:
@ -255,6 +257,10 @@ async def sample_and_broadcast(
subs.remove((stream, tick_throttle))
# TODO: a less naive throttler, here's some snippets:
# token bucket by njs:
# https://gist.github.com/njsmith/7ea44ec07e901cb78ebe1dd8dd846cb9
async def uniform_rate_send(
rate: float,
@ -292,7 +298,7 @@ async def uniform_rate_send(
rate = 1 / (now - last_send)
last_send = now
# print(f'{rate} Hz sending quotes\n{first_quote}')
# print(f'{rate} Hz sending quotes') # \n{first_quote}')
# TODO: now if only we could sync this to the display
# rate timing exactly lul