Make update_first configurable
This commit is contained in:
parent
e6dd40bff0
commit
a021916428
|
@ -28,6 +28,9 @@ class ThreadedDocumenter(autodoc.FunctionDocumenter):
|
||||||
if isinstance(self.object, ThreadedSegment):
|
if isinstance(self.object, ThreadedSegment):
|
||||||
args = ['interval']
|
args = ['interval']
|
||||||
defaults = [getattr(self.object, 'interval', 1)]
|
defaults = [getattr(self.object, 'interval', 1)]
|
||||||
|
if self.object.update_first:
|
||||||
|
args.append('update_first')
|
||||||
|
defaults.append(True)
|
||||||
methods = ['render', 'set_state']
|
methods = ['render', 'set_state']
|
||||||
if isinstance(self.object, KwThreadedSegment):
|
if isinstance(self.object, KwThreadedSegment):
|
||||||
methods += ['key', 'render_one']
|
methods += ['key', 'render_one']
|
||||||
|
@ -41,7 +44,8 @@ class ThreadedDocumenter(autodoc.FunctionDocumenter):
|
||||||
if (arg == 'self' or
|
if (arg == 'self' or
|
||||||
(arg == 'segment_info' and
|
(arg == 'segment_info' and
|
||||||
getattr(self.object, 'powerline_requires_segment_info', None)) or
|
getattr(self.object, 'powerline_requires_segment_info', None)) or
|
||||||
(method == 'render_one' and -i == len(argspec.args))):
|
(method == 'render_one' and -i == len(argspec.args)) or
|
||||||
|
arg in args):
|
||||||
continue
|
continue
|
||||||
if argspec.defaults and len(argspec.defaults) >= -i:
|
if argspec.defaults and len(argspec.defaults) >= -i:
|
||||||
default = argspec.defaults[i]
|
default = argspec.defaults[i]
|
||||||
|
|
|
@ -67,14 +67,14 @@ class ThreadedSegment(object):
|
||||||
self.interval = interval
|
self.interval = interval
|
||||||
self.has_set_interval = True
|
self.has_set_interval = True
|
||||||
|
|
||||||
def set_state(self, interval=None, **kwargs):
|
def set_state(self, update_first=True, interval=None, **kwargs):
|
||||||
if not self.did_set_interval or interval:
|
if not self.did_set_interval or interval:
|
||||||
self.set_interval(interval)
|
self.set_interval(interval)
|
||||||
# Without this we will not have to wait long until receiving bug “I
|
# Without this we will not have to wait long until receiving bug “I
|
||||||
# opened vim, but branch information is only shown after I move cursor”.
|
# opened vim, but branch information is only shown after I move cursor”.
|
||||||
#
|
#
|
||||||
# If running once .update() is called in __call__.
|
# If running once .update() is called in __call__.
|
||||||
if self.update_first and not self.run_once:
|
if update_first and self.update_first and not self.run_once:
|
||||||
self.update_first = False
|
self.update_first = False
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
@ -99,7 +99,6 @@ def printed(func):
|
||||||
|
|
||||||
class KwThreadedSegment(ThreadedSegment):
|
class KwThreadedSegment(ThreadedSegment):
|
||||||
drop_interval = 10 * 60
|
drop_interval = 10 * 60
|
||||||
update_missing = True
|
|
||||||
update_first = False
|
update_first = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -115,9 +114,7 @@ class KwThreadedSegment(ThreadedSegment):
|
||||||
try:
|
try:
|
||||||
update_state = self.queries[key][1]
|
update_state = self.queries[key][1]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# self.update_missing has the same reasoning as self.update_first in
|
update_state = self.compute_state(key) if self.update_first or self.run_once else None
|
||||||
# parent class
|
|
||||||
update_state = self.compute_state(key) if self.update_missing or self.run_once else None
|
|
||||||
# No locks: render method is already running with write_lock acquired.
|
# No locks: render method is already running with write_lock acquired.
|
||||||
self.queries[key] = (monotonic(), update_state)
|
self.queries[key] = (monotonic(), update_state)
|
||||||
return self.render_one(update_state, **kwargs)
|
return self.render_one(update_state, **kwargs)
|
||||||
|
@ -135,13 +132,18 @@ class KwThreadedSegment(ThreadedSegment):
|
||||||
for key in removes:
|
for key in removes:
|
||||||
self.queries.pop(key)
|
self.queries.pop(key)
|
||||||
|
|
||||||
def set_state(self, interval=None, **kwargs):
|
def set_state(self, update_first=True, interval=None, **kwargs):
|
||||||
if not self.did_set_interval or (interval < self.interval):
|
if not self.did_set_interval or (interval < self.interval):
|
||||||
self.set_interval(interval)
|
self.set_interval(interval)
|
||||||
|
|
||||||
|
# Allow only to forbid to compute missing values: in either user
|
||||||
|
# configuration or in subclasses.
|
||||||
|
if self.update_first:
|
||||||
|
self.update_first = update_first
|
||||||
|
|
||||||
key = self.key(**kwargs)
|
key = self.key(**kwargs)
|
||||||
if not self.run_once and key not in self.queries:
|
if not self.run_once and key not in self.queries:
|
||||||
self.queries[key] = (monotonic(), self.compute_state(key) if self.update_missing else None)
|
self.queries[key] = (monotonic(), self.compute_state(key) if self.update_first else None)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def render_one(update_state, **kwargs):
|
def render_one(update_state, **kwargs):
|
||||||
|
|
Loading…
Reference in New Issue