Skip to content

Commit

Permalink
Use @decorator in @time_limit decorator to remove function nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed May 19, 2024
1 parent 3c70778 commit a986f00
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions plextraktsync/decorators/time_limit.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
from functools import wraps

from plextraktsync.config import TRAKT_POST_DELAY
from plextraktsync.util.Timer import Timer
from decorator import decorator


timer = Timer(TRAKT_POST_DELAY)


def time_limit():
@decorator
def time_limit(fn, *args, **kwargs):
"""
Throttles calls not to be called more often than TRAKT_POST_DELAY
"""
timer.wait_if_needed()

def decorator(fn):
@wraps(fn)
def wrapper(*args, **kwargs):
timer.wait_if_needed()
return fn(*args, **kwargs)

return wrapper

return decorator
return fn(*args, **kwargs)

0 comments on commit a986f00

Please sign in to comment.