Skip to content

Commit

Permalink
Address review feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigogiraoserrao committed Jun 9, 2023
1 parent 6f31380 commit 0c32c05
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/textual/_time.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import platform
import asyncio
import platform
from asyncio import sleep as asyncio_sleep
from time import monotonic, perf_counter

Expand All @@ -26,7 +26,9 @@ async def sleep(secs: float) -> None:
Args:
secs: Number of seconds to sleep for.
"""
await asyncio.create_task(win_sleep(secs))
sleep = win_sleep(secs)
if sleep is not None:
await asyncio.create_task(sleep)

else:

Expand Down
6 changes: 4 additions & 2 deletions src/textual/_win_sleep.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
This should only be imported on Windows.
"""

from __future__ import annotations

import asyncio
from time import sleep as time_sleep
from typing import Coroutine
Expand Down Expand Up @@ -35,7 +37,7 @@ def sleep(secs: float) -> Coroutine[None, None, None]:

else:

def sleep(secs: float) -> Coroutine[None, None, None]:
def sleep(secs: float) -> Coroutine[None, None, None] | None:
"""A replacement sleep for Windows.
Note that unlike `time.sleep` this *may* sleep for slightly less than the
Expand All @@ -49,7 +51,7 @@ def sleep(secs: float) -> Coroutine[None, None, None]:
sleep_for = max(0, secs - 0.001)
if sleep_for < 0.0005:
# Less than 0.5ms and its not worth doing the sleep
return time_sleep_coro(0)
return None

timer = kernel32.CreateWaitableTimerExW(
None,
Expand Down

0 comments on commit 0c32c05

Please sign in to comment.