Last active
March 31, 2020 20:35
-
-
Save numberoverzero/f09e8eec841702f00464c6d249c81e65 to your computer and use it in GitHub Desktop.
accordian api change
This file contains hidden or 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
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 |
This file contains hidden or 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
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) |
This file contains hidden or 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
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