From 8d0e6d8c5cedd32c996f6f1166718474af0036e6 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 8 Apr 2019 20:30:11 +0200 Subject: [PATCH] Create sleep_until --- royalnet/utils/sleepuntil.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 royalnet/utils/sleepuntil.py diff --git a/royalnet/utils/sleepuntil.py b/royalnet/utils/sleepuntil.py new file mode 100644 index 00000000..7b6189cb --- /dev/null +++ b/royalnet/utils/sleepuntil.py @@ -0,0 +1,10 @@ +import asyncio +import datetime + + +async def sleep_until(dt: datetime.datetime): + now = datetime.datetime.now() + if now > dt: + return + delta = dt - now + await asyncio.sleep(delta.total_seconds())