Skip to content

Commit

Permalink
Polish PyGameScheduler, typing and docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
erikkemperman committed Mar 15, 2019
1 parent 8e27fbe commit 7dd1df7
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions rx/concurrency/mainloopscheduler/pygamescheduler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from datetime import datetime
from typing import Any, List
from typing import Optional
import threading

from rx.internal import PriorityQueue
Expand All @@ -27,20 +27,32 @@ def __init__(self):
self._lock = threading.Lock()
self._queue: PriorityQueue[ScheduledItem[typing.TState]] = PriorityQueue()

def schedule(self, action: typing.ScheduledAction, state: Any = None) -> typing.Disposable:
"""Schedules an action to be executed."""
def schedule(self,
action: typing.ScheduledAction,
state: Optional[typing.TState] = None
) -> typing.Disposable:
"""Schedules an action to be executed.
Args:
action: Action to be executed.
state: [Optional] state to be given to the action function.
Returns:
The disposable object used to cancel the scheduled action
(best effort).
"""

log.debug("PyGameScheduler.schedule(state=%s)", state)
return self.schedule_absolute(self.now, action, state)

def schedule_relative(self, duetime: typing.RelativeTime, action: typing.ScheduledAction,
state: typing.TState = None) -> typing.Disposable:
def schedule_relative(self,
duetime: typing.RelativeTime,
action: typing.ScheduledAction,
state: Optional[typing.TState] = None
) -> typing.Disposable:
"""Schedules an action to be executed after duetime.
Args:
duetime: Relative time after which to execute the action.
action: Action to be executed.
state: [Optional] state to be given to the action function.
Returns:
The disposable object used to cancel the scheduled action
(best effort).
Expand All @@ -49,17 +61,17 @@ def schedule_relative(self, duetime: typing.RelativeTime, action: typing.Schedul
duetime = SchedulerBase.normalize(self.to_timedelta(duetime))
return self.schedule_absolute(self.now + duetime, action, state=state)

def schedule_absolute(self, duetime: typing.AbsoluteTime, action: typing.ScheduledAction,
state: typing.TState = None) -> typing.Disposable:
def schedule_absolute(self, duetime: typing.AbsoluteTime,
action: typing.ScheduledAction,
state: Optional[typing.TState] = None
) -> typing.Disposable:
"""Schedules an action to be executed at duetime.
Args:
duetime: Absolute time after which to execute the action.
action: Action to be executed.
Returns:
The disposable object used to cancel the scheduled action
(best effort)."""
state: [Optional] state to be given to the action function.
"""

duetime = self.to_datetime(duetime)
si: ScheduledItem[typing.TState] = ScheduledItem(self, state, action, duetime)
Expand Down

0 comments on commit 7dd1df7

Please sign in to comment.