Philipp Hörist pushed to branch master at gajim / gajim
Commits:
53880edd by Philipp Hörist at 2019-04-14T20:32:47Z
Add delay execution decorator
- - - - -
1 changed file:
- gajim/common/helpers.py
Changes:
=====================================
gajim/common/helpers.py
=====================================
@@ -50,9 +50,11 @@ from datetime import datetime, timedelta
from distutils.version import LooseVersion as V
from encodings.punycode import punycode_encode
from string import Template
+from functools import wraps
import nbxmpp
from nbxmpp.stringprepare import nameprep
+from gi.repository import GLib
import precis_i18n.codec # pylint: disable=unused-import
from gajim.common import app
@@ -1532,3 +1534,21 @@ class Singleton(type):
cls._instances[cls] = super(Singleton, cls).__call__(
*args, **kwargs)
return cls._instances[cls]
+
+
+def delay_execution(milliseconds):
+ # Delay the first call for `milliseconds`
+ # ignore all other calls while the delay is active
+ def delay_execution_decorator(func):
+ @wraps(func)
+ def func_wrapper(*args, **kwargs):
+ def timeout_wrapper():
+ func(*args, **kwargs)
+ delattr(func_wrapper, 'source_id')
+
+ if hasattr(func_wrapper, 'source_id'):
+ return
+ func_wrapper.source_id = GLib.timeout_add(
+ milliseconds, timeout_wrapper)
+ return func_wrapper
+ return delay_execution_decorator
View it on GitLab:
https://dev.gajim.org/gajim/gajim/commit/53880edd96f270f42562b92b64c21a3fd2d9dcc3
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/commit/53880edd96f270f42562b92b64c21a3fd2d9dcc3
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits