Skip to content

Instantly share code, notes, and snippets.

@numberoverzero
Last active March 31, 2020 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save numberoverzero/f09e8eec841702f00464c6d249c81e65 to your computer and use it in GitHub Desktop.
Save numberoverzero/f09e8eec841702f00464c6d249c81e65 to your computer and use it in GitHub Desktop.
accordian api change
Namespace
.signal(name) -> Signal
Signal
.connect(async fn) -> async fn
.send(*a, **kw) -> Set[Task]
async .join(*a, **kw) -> List[Any]
_global = Namespace()
signal = _global.Signal
import math
from sample_api import signal
check_price = signal("check-price")
@check_price.connect
async def recent_check(prod, qty):
return "recent", await db.get("recent", prod)
@check_price.connect
async def minimum_check(prod, qty):
return "min", 0.01
@check_price.connect
async def bulk_check(prod, qty):
_, recent = await recent_check(prod, qty)
discount = [0, 3, 7, 11, 15]
i = int(math.log10(qty))
i = min(i, len(discount))
return "bulk", recent * (1 - discount[i]/100)
from sample_receivers import check_price
async def price_check_handler(prod, qty):
prices = await check_price.join(prod, qty)
return [(src, p*qty) for (src, p) in prices]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment