-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use @decorator in @time_limit decorator to remove function nesting
- Loading branch information
Showing
1 changed file
with
6 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |