diff options
author | Ralph Bean <rbean@redhat.com> | 2013-01-10 13:33:18 -0500 |
---|---|---|
committer | Ralph Bean <rbean@redhat.com> | 2013-01-10 13:33:18 -0500 |
commit | a206305830ebaf7f38df836d15b41704c9ce989c (patch) | |
tree | 84310438af6607632a012f25f50588421f375b0c | |
parent | 04dec794d4c0157dae5b0716ae6884189334673b (diff) | |
download | dogpile-core-a206305830ebaf7f38df836d15b41704c9ce989c.tar.gz |
Rework background_runner as async_creator.
-rw-r--r-- | dogpile/core/dogpile.py | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/dogpile/core/dogpile.py b/dogpile/core/dogpile.py index b326724..5d6e2b7 100644 --- a/dogpile/core/dogpile.py +++ b/dogpile/core/dogpile.py @@ -46,11 +46,11 @@ class Lock(object): ``None`` for never expires. This timestamp is compared to the creation_time result and ``time.time()`` to determine if the value returned by value_and_created_fn is "expired". - :param background_runner: A callable. If specified, this callable will be - passed the mutex and creator callable as arguments. Responsibility for - releasing the mutex is delegated to this callable. The intent is for this - to be used to defer invocation of the creator callable until some later - time: to run it in the background. + :param async_creator: A callable. If specified, this callable will be + passed the mutex as an argument and is responsible for releasing the mutex + after it finishes some asynchronous value creation. The intent is for + this to be used to defer invocation of the creator callable until some + later time. """ @@ -59,13 +59,13 @@ class Lock(object): creator, value_and_created_fn, expiretime, - background_runner=None, + async_creator=None, ): self.mutex = mutex self.creator = creator self.value_and_created_fn = value_and_created_fn self.expiretime = expiretime - self.background_runner = background_runner + self.async_creator = async_creator def _is_expired(self, createdtime): """Return true if the expiration time is reached, or no @@ -114,7 +114,7 @@ class Lock(object): if not self._is_expired(createdtime): return NOT_REGENERATED - backgrounded = False + async = False if self._has_value(createdtime): if not self.mutex.acquire(False): @@ -137,17 +137,17 @@ class Lock(object): if not self._is_expired(createdtime): log.debug("value already present") return value, createdtime - elif self.background_runner: - log.debug("Passing creation lock to background runner") - self.background_runner(self.mutex, self.creator) - backgrounded = True + elif self.async_creator: + log.debug("Passing creation lock to async runner") + self.async_creator(self.mutex) + async = True return value, createdtime log.debug("Calling creation function") created = self.creator() return created finally: - if not backgrounded: + if not async: self.mutex.release() log.debug("Released creation lock") |