summaryrefslogtreecommitdiff
path: root/taskflow/utils/misc.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@yahoo-inc.com>2015-04-02 11:15:06 -0700
committerJoshua Harlow <harlowja@gmail.com>2015-05-01 21:33:21 -0700
commit530328a86c3fe7be7235c602332d0bd823e29dbe (patch)
treefbd39f97e8d2b96bed5500ce053c8fc5cf136386 /taskflow/utils/misc.py
parent426d08f9516e1f93cde3a4f09d12b3d5da53b1dd (diff)
downloadtaskflow-530328a86c3fe7be7235c602332d0bd823e29dbe.tar.gz
Refactor/reduce shared 'ensure(task/retry)' code
These methods are nearly identical so we should refactor them to use the same code for sanity and understanding purposes. Change-Id: Ibaf270bd451b6d02d7782901bc2327afe04d3847
Diffstat (limited to 'taskflow/utils/misc.py')
-rw-r--r--taskflow/utils/misc.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/taskflow/utils/misc.py b/taskflow/utils/misc.py
index ee5fb39..d79fe8f 100644
--- a/taskflow/utils/misc.py
+++ b/taskflow/utils/misc.py
@@ -88,14 +88,18 @@ def find_monotonic(allow_time_time=False):
return None
-def match_type_handler(item, type_handlers):
- """Matches a given items type using the given match types + handlers.
+def match_type(obj, matchers):
+ """Matches a given object using the given matchers list/iterable.
- Returns the handler if a type match occurs, otherwise none.
+ NOTE(harlowja): each element of the provided list/iterable must be
+ tuple of (valid types, result).
+
+ Returns the result (the second element of the provided tuple) if a type
+ match occurs, otherwise none if no matches are found.
"""
- for (match_types, handler_func) in type_handlers:
- if isinstance(item, match_types):
- return handler_func
+ for (match_types, match_result) in matchers:
+ if isinstance(obj, match_types):
+ return match_result
else:
return None