fixes
This commit is contained in:
32
parseq.cm
32
parseq.cm
@@ -29,7 +29,7 @@ function is_requestor (fn) {
|
||||
}
|
||||
|
||||
function check_requestors (list, factory) {
|
||||
if (!isa(list, array) || list.some(r => !is_requestor(r)))
|
||||
if (!is_array(list) || list.some(r => !is_requestor(r)))
|
||||
throw make_reason(factory, 'Bad requestor list.', list)
|
||||
}
|
||||
|
||||
@@ -47,9 +47,9 @@ function schedule (fn, seconds) {
|
||||
// ———————————————————————————————————————— core runner
|
||||
|
||||
function run (factory, requestors, initial, action, time_limit, throttle = 0) {
|
||||
let cancel_list = new Array(requestors.length)
|
||||
let next = 0
|
||||
let timer_cancel
|
||||
var cancel_list = new Array(requestors.length)
|
||||
var next = 0
|
||||
var timer_cancel
|
||||
|
||||
function cancel (reason = make_reason(factory, 'Cancel.')) {
|
||||
if (timer_cancel) timer_cancel(), timer_cancel = null
|
||||
@@ -60,7 +60,7 @@ function run (factory, requestors, initial, action, time_limit, throttle = 0) {
|
||||
|
||||
function start_requestor (value) {
|
||||
if (!cancel_list || next >= requestors.length) return
|
||||
let idx = next++
|
||||
var idx = next++
|
||||
def req = requestors[idx]
|
||||
|
||||
try {
|
||||
@@ -87,7 +87,7 @@ function run (factory, requestors, initial, action, time_limit, throttle = 0) {
|
||||
}
|
||||
|
||||
def concurrent = throttle ? number.min(throttle, requestors.length) : requestors.length
|
||||
for (let i = 0; i < concurrent; i++) start_requestor(initial)
|
||||
for (var i = 0; i < concurrent; i++) start_requestor(initial)
|
||||
|
||||
return cancel
|
||||
}
|
||||
@@ -95,10 +95,10 @@ function run (factory, requestors, initial, action, time_limit, throttle = 0) {
|
||||
// ———————————————————————————————————————— factories
|
||||
|
||||
function _normalize (collection, factory) {
|
||||
if (isa(collection)) return { names: null, list: collection }
|
||||
if (is_array(collection)) return { names: null, list: collection }
|
||||
if (collection && is_object(collection)) {
|
||||
def names = array(collection)
|
||||
def list = names.map(k => collection[k]).filter(is_requestor)
|
||||
def list = names.map(k => collection[k]).filter(is_requestor)
|
||||
return { names, list }
|
||||
}
|
||||
throw make_reason(factory, 'Expected array or record.', collection)
|
||||
@@ -119,7 +119,7 @@ function par_all (collection, time_limit, throttle) {
|
||||
|
||||
return function par_all_req (cb, initial) {
|
||||
check_callback(cb, factory)
|
||||
let pending = list.length
|
||||
var pending = list.length
|
||||
def results = new Array(list.length)
|
||||
|
||||
def cancel = run(factory, list, initial, (val, reason, idx) => {
|
||||
@@ -143,7 +143,7 @@ function par_any (collection, time_limit, throttle) {
|
||||
|
||||
return function par_any_req (cb, initial) {
|
||||
check_callback(cb, factory)
|
||||
let pending = list.length
|
||||
var pending = list.length
|
||||
def successes = new Array(list.length)
|
||||
|
||||
def cancel = run(factory, list, initial, (val, reason, idx) => {
|
||||
@@ -161,14 +161,14 @@ function par_any (collection, time_limit, throttle) {
|
||||
}
|
||||
|
||||
function race (list, time_limit, throttle) {
|
||||
def factory = throttle == 1 ? 'fallback' : 'race'
|
||||
if (!isa(list, array) || list.length == 0)
|
||||
def factory = throttle == 1 ? 'fallback' : 'race'
|
||||
if (!is_array(list) || list.length == 0)
|
||||
throw make_reason(factory, 'No requestors.')
|
||||
check_requestors(list, factory)
|
||||
|
||||
return function race_req (cb, initial) {
|
||||
check_callback(cb, factory)
|
||||
let done = false
|
||||
var done = false
|
||||
def cancel = run(factory, list, initial, (val, reason, idx) => {
|
||||
if (done) return
|
||||
if (val != null) {
|
||||
@@ -190,14 +190,14 @@ function fallback (list, time_limit) {
|
||||
}
|
||||
|
||||
function sequence (list, time_limit) {
|
||||
def factory = 'sequence'
|
||||
if (!isa(list, array)) throw make_reason(factory, 'Not an array.', list)
|
||||
def factory = 'sequence'
|
||||
if (!is_array(list)) throw make_reason(factory, 'Not an array.', list)
|
||||
check_requestors(list, factory)
|
||||
if (list.length == 0) return (cb, v) => cb(v)
|
||||
|
||||
return function sequence_req (cb, initial) {
|
||||
check_callback(cb, factory)
|
||||
let idx = 0
|
||||
var idx = 0
|
||||
|
||||
function next (value) {
|
||||
if (idx >= list.length) return cb(value)
|
||||
|
||||
Reference in New Issue
Block a user