Fix behavior with run_once: .update() was called too much times

This commit is contained in:
ZyX 2013-03-20 08:58:25 +04:00
parent a65a27e673
commit e6dd40bff0
1 changed files with 5 additions and 3 deletions

View File

@ -72,7 +72,9 @@ class ThreadedSegment(object):
self.set_interval(interval)
# 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”.
if self.update_first:
#
# If running once .update() is called in __call__.
if self.update_first and not self.run_once:
self.update_first = False
self.update()
@ -115,7 +117,7 @@ class KwThreadedSegment(ThreadedSegment):
except KeyError:
# self.update_missing has the same reasoning as self.update_first in
# parent class
update_state = self.compute_state(key) if self.update_missing else None
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.
self.queries[key] = (monotonic(), update_state)
return self.render_one(update_state, **kwargs)
@ -138,7 +140,7 @@ class KwThreadedSegment(ThreadedSegment):
self.set_interval(interval)
key = self.key(**kwargs)
if 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)
@staticmethod