This commit is contained in:
2026-01-19 01:06:45 -06:00
parent 5271688dd4
commit cbf99295da
16 changed files with 69 additions and 121 deletions

View File

@@ -319,45 +319,12 @@ function requestorize(unary) {
}
}
// objectify(factory_fn)
// Converts a factory that takes arrays to one that takes objects.
function objectify(factory_fn) {
def factory = 'objectify'
if (!is_function(factory_fn))
throw make_reason(factory, 'Not a factory.', factory_fn)
return function objectified_factory(object_of_requestors, ...rest) {
if (!is_object(object_of_requestors))
throw make_reason(factory, 'Expected an object.', object_of_requestors)
def keys = array(object_of_requestors)
def requestor_array = array(keys, k => object_of_requestors[k])
def inner_requestor = factory_fn(requestor_array, ...rest)
return function(callback, value) {
return inner_requestor(function(results, reason) {
if (results == null) {
callback(null, reason)
} else if (is_array(results)) {
def obj = {}
arrfor(keys, (k, i) => { obj[k] = results[i] })
callback(obj, reason)
} else {
callback(results, reason)
}
}, value)
}
}
}
return {
fallback,
parallel,
race,
sequence,
requestorize,
objectify,
is_requestor,
check_callback
}