From 526f2872012b42d634faaaee916e1e050d07a5c9 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Thu, 12 Mar 2015 15:18:36 -0700 Subject: [PATCH] Allow passing 'many_handler' to fetch_all function When many values are found for a given result a callback is called to determine what to return. To match the fetch routine allow for the fetch_all function to pass along a handler (and default to one that is the existing behavior) so that people can extract there own values (if they so choose). Change-Id: I8c105e1a810e8e0c2c210613506c9ce59021009d --- taskflow/storage.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/taskflow/storage.py b/taskflow/storage.py index 3cf496aa..4b9b80dd 100644 --- a/taskflow/storage.py +++ b/taskflow/storage.py @@ -644,11 +644,13 @@ class Storage(object): @lock_utils.read_locked def fetch(self, name, many_handler=None): """Fetch a named result.""" - # By default we just return the first of many (unless provided - # a different callback that can translate many results into something - # more meaningful). + def _many_handler(values): + # By default we just return the first of many (unless provided + # a different callback that can translate many results into + # something more meaningful). + return values[0] if many_handler is None: - many_handler = lambda values: values[0] + many_handler = _many_handler try: providers = self._reverse_mapping[name] except KeyError: @@ -758,12 +760,14 @@ class Storage(object): return missing @lock_utils.read_locked - def fetch_all(self): + def fetch_all(self, many_handler=None): """Fetch all named results known so far.""" - def many_handler(values): + def _many_handler(values): if len(values) > 1: return values return values[0] + if many_handler is None: + many_handler = _many_handler results = {} for name in six.iterkeys(self._reverse_mapping): try: