Skip to content

Commit

Permalink
default token support
Browse files Browse the repository at this point in the history
  • Loading branch information
pomponchik committed Jul 17, 2024
1 parent 57e3954 commit 9678103
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions metronomes/metronome.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@

import escape
from emptylog import EmptyLogger, LoggerProtocol
from cantok import AbstractToken, SimpleToken, TimeoutToken
from cantok import AbstractToken, SimpleToken, DefaultToken, TimeoutToken
from locklib import ContextLockProtocol

from metronomes.errors import RunStoppedMetronomeError, RunAlreadyStartedMetronomeError, StopNotStartedMetronomeError, StopStoppedMetronomeError


class Metronome:
def __init__(self, iteration: Union[int, float], callback: Callable[[], Any], suppress_exceptions: bool = True, logger: LoggerProtocol = EmptyLogger(), token: Optional[AbstractToken] = None, lock_factory: Union[Type[ContextLockProtocol], Callable[[], ContextLockProtocol]] = RLock, sleeping_callback: Callable[[Union[int, float]], Any] = sleep, duration: Optional[Union[int, float]] = None) -> None:
def __init__(self, iteration: Union[int, float], callback: Callable[[], Any], suppress_exceptions: bool = True, logger: LoggerProtocol = EmptyLogger(), token: AbstractToken = DefaultToken(), lock_factory: Union[Type[ContextLockProtocol], Callable[[], ContextLockProtocol]] = RLock, sleeping_callback: Callable[[Union[int, float]], Any] = sleep, duration: Optional[Union[int, float]] = None) -> None:
if iteration <= 0:
raise ValueError('The duration of the metronome iteration (tick-tock time) must be greater than zero.')

self.iteration: Union[int, float] = iteration
self.callback: Callable[[], Any] = callback
self.suppress_exceptions: bool = suppress_exceptions
self.logger: LoggerProtocol = logger
self.token: AbstractToken = SimpleToken(token) if token is not None else SimpleToken()
self.token: AbstractToken = SimpleToken(token)
if duration is not None:
if duration < 0:
raise ValueError('The total duration of the metronome operation cannot be less than zero.')
Expand Down

0 comments on commit 9678103

Please sign in to comment.