Makes an async function that takes 3 arguments only execute one at a time.
170095
function safe3(fn) {
  var queue = Queue.new();
  var safe = true;
  function checkQueue() {
    var next = queue.shift();
    safe = false;
    fn(next[0], next[1], next[2], function (error, result) {
      next[3](error, result);
      if (queue.length > 0) {
        checkQueue();
      } else {
        safe = true;
      }
    });
  }
  return function (arg1, arg2, arg3, callback) {
    queue.push(arguments);
    if (safe) {
      checkQueue();
    }
  };
}
214159
function () {

    var after = {
        loop: function (condition) {
            if (!utils.isFunction(condition)) {
                throw new Error('Asynk loop function require a function as first argument');
            }
            _Context.loopDefer = _Context.loopDefer || new Deferred();
            _Context.loopResults = _Context.loopResults || [];
            this.done(function () {
                var result = utils.toArray(arguments);
                if (result.length > 1) {

                    _Context.loopResults.push(result);
                }
                else {
                    _Context.loopResults.push(result[0]);
                }

                if (condition.apply(null, result)) {
                    //reset values
                    for (var i in _Context.tasks) {
                        _Context.tasks[i].status = WAITING;
                    }
                    _Context.results = [];
                    _Context.currentTasks = [];
                    _Context.exec.fct.apply(null, _Context.exec.args).loop(condition);
                }
                else {
                    _Context.loopDefer.resolve(_Context.loopResults);
                }
            });
            this.fail(_Context.loopDefer.reject);
            return _Context.loopDefer.promise();
        },
        asyncLoop: function (condition) {
            if (!utils.isFunction(condition)) {
                throw new Error('Asynk loop function require a function as first argument');
            }
            _Context.loopDefer = _Context.loopDefer || new Deferred();
            _Context.loopResults = _Context.loopResults || [];
            this.done(function () {
                var result;
                if (arguments.length > 1) {
                    result = utils.toArray(arguments);
                }
                else {
                    result = arguments[0];
                }
                _Context.loopResults.push(result);
                
                condition.apply(null, [result, function (err, loop) {
                    if (err) {
                        return _Context.loopDefer.reject(err);
                    }
                    if (loop) {
                        //reset values
                        for (var i in _Context.tasks) {
                            _Context.tasks[i].status = WAITING;
                        }
                        _Context.results = [];
                        _Context.currentTasks = [];
                        _Context.exec.fct.apply(null, _Context.exec.args).asyncLoop(condition);
                    }
                    else {
                        _Context.loopDefer.resolve(_Context.loopResults);
                    }
                }]);
            });
            this.fail(_Context.loopDefer.reject);
            return _Context.loopDefer.promise();
        }
    };

    var Asynk = {};

    var _Context = {
        tasks: [],
        aliasMap: {},
        results: [],
        currentTasks: Asynk.currentTasks
    };

    Asynk.add = function (fct) {
        if (utils.isUndefined(fct) || !utils.isFunction(fct)) {
            throw new Error('Asynk add require a function as argument');
        }
        var newId = _Context.tasks.length;
        _Context.tasks[newId] = new Task(_Context, newId, fct);
        _Context.currentTasks = [newId];
        this.args(new DefArg('callback'));
        return this;
    };

    Asynk.each = function (datas, fct) {
        if (utils.isUndefined(fct) || !utils.isFunction(fct)) {
            throw new Error('Asynk each require a function as second argument');
        }
        _Context.currentTasks = [];
        datas.forEach(function (data) {
            var newId = _Context.tasks.length;
            _Context.tasks[newId] = new Task(_Context, newId, fct);
            _Context.tasks[newId].item = data;
            _Context.currentTasks.push(newId);
        });
        this.args(new DefArg('item'), new DefArg('callback'));
        return this;
    };

    Asynk.args = function () {
        var args = utils.toArray(arguments);
        _Context.currentTasks.forEach(function(currentTask) {
            _Context.tasks[currentTask].args = utils.toArray(args);
        });
        return this;
    };

    Asynk.require = function (dependencies) {
        if (!utils.isArray(dependencies)) {
          dependencies = [dependencies];
        }
        _Context.currentTasks.forEach(function(currentTask) {
            var current = _Context.tasks[currentTask];
            current.dependencies = current.dependencies.concat(dependencies);
        });
        return this;
    };

    Asynk.alias = function (alias) {
        if (utils.isString(alias)) {
            _Context.currentTasks.forEach(function (currentTask, index) {
                _Context.tasks[currentTask].alias = alias;
            });
            if (_Context.currentTasks.length > 1) {
                _Context.aliasMap[alias] = _Context.currentTasks;
            }
            else {
                _Context.aliasMap[alias] = _Context.currentTasks[0];
            }
        }
        return this;
    };

    Asynk.serie = function(endcallArgs) {
        _Context.exec = {
            fct: Asynk.serie,
            args: [endcallArgs]
        };
        var defer = new Deferred();
        var endTask = new Task(_Context, 'end', defer.resolve.bind(defer));
        endTask.args = endcallArgs || [new DefArg('alias', 'all')];
        var currentId = 0;

        var cb = function (err, data) {
            if (err) {
                _Context.tasks[currentId].status = FAIL;
                defer.reject(err);
                endTask.reject(err);
                return;
            }
            _Context.tasks[currentId].status = DONE;
            _Context.results.push(data);
            currentId++;
            next();
        };
        var next = function() {
            var current = _Context.tasks[currentId];
            if (current) {
                current.setCallback(cb);
                current.execute();
                if (current.status === WAITING_FOR_DEPENDENCY) {
                    defer.reject(new Error('could not resolve this dependancies'));
                }
            }
            else {
                endTask.execute();
            }
        };
        next();
        return defer.promise(after);
    };

    Asynk.parallel = function(endcallArgs) {
        _Context.exec = {
            fct: Asynk.parallel,
            args: [endcallArgs]
        };
        var defer = new Deferred();
        var endTask = new Task(_Context, 'end', defer.resolve.bind(defer));
        endTask.args = endcallArgs || [new DefArg('alias', 'all')];

        var count = 0;
        var todo = _Context.tasks.length;
        var cb = function (task, err, data) {
            task.status = DONE;
            if (err) {
                defer.reject(err);
                endTask.reject(err);
                return;
            }
            _Context.results[task.id] = data;
            count++;
            if (count >= todo) {
                endTask.execute();
            }
            else {
                _Context.tasks.forEach(function(task) {
                    if (task.status === WAITING_FOR_DEPENDENCY) {
                        task.execute();
                    }
                });
            }
        };

        if (_Context.tasks.length === 0) {
            endTask.execute();
            return defer.promise();
        }

        _Context.tasks.forEach(function(task) {
            task.setCallback(function (err, data) {
                cb(task, err, data);
            });
        });

        _Context.tasks.forEach(function(task) {
            task.execute();
        });

        return defer.promise(after);
    };

    Asynk.parallelLimited = function(limit, endcallArgs) {
        _Context.exec = {
            fct: Asynk.parallelLimited,
            args: [limit, endcallArgs]
        };
        var defer = new Deferred();
        var endTask = new Task(_Context, 'end', defer.resolve.bind(defer));
        endTask.args = endcallArgs || [new DefArg('alias', 'all')];

        var count = 0;
        var todo = _Context.tasks.length;
        var cb = function (task, err, data) {
            task.status = DONE;
            if (err) {
                defer.reject(err);
                endTask.reject(err);
                return;
            }
            _Context.results[task.id] = data;
            count++;
            if (count >= todo) {
                endTask.execute();
            }
            else {
                _Context.tasks.forEach(function(task) {
                    var stats = utils.countBy(_Context.tasks, function(task) {
                        return task.status;
                    });
                    var running = stats[RUNNING] || 0;
                    if ((running < limit) && (task.status < RUNNING)) {
                        task.execute();
                    }
                });
            }
        };

        if (_Context.tasks.length === 0) {
            endTask.execute();
            return defer.promise();
        }

        _Context.tasks.forEach(function(task) {
            task.setCallback(function (err, data) {
                cb(task, err, data);
            });
        });

        _Context.tasks.forEach(function(task) {
            var stats = utils.countBy(_Context.tasks, function(task) {
                return task.status;
            });
            var running = stats[RUNNING] || 0;
            if ((running < limit) && (task.status < RUNNING)) {
                task.execute();
            }
        });

        return defer.promise(after);
    };

    return Asynk;
}
775005
function(func, context, argCount) {
                if (context === void 0) return func;
                switch (argCount == null ? 3 : argCount) {
                  case 1: return function(value) {
                    return func.call(context, value);
                  };
                  case 2: return function(value, other) {
                    return func.call(context, value, other);
                  };
                  case 3: return function(value, index, collection) {
                    return func.call(context, value, index, collection);
                  };
                  case 4: return function(accumulator, value, index, collection) {
                    return func.call(context, accumulator, value, index, collection);
                  };
                }
                return function() {
                  return func.apply(context, arguments);
                };
              }
957229
def _async_callable(func):
    """"""
    if isinstance(func, types.CoroutineType):

        return func

    @functools.wraps(func)
    async def _async_def_wrapper(*args, **kwargs):
        """Wrap a a sync callable in an async def."""
        return func(*args, **kwargs)

    return _async_def_wrapper
1234384
function doAsyncBench(fn, callback) {

		var fnOverhead,
		    pretotal,
		    result,
		    args,
		    i;

		if (benchRunning > 0) {

			// Keep function optimized by not leaking the `arguments` object
			args = new Array(arguments.length);
			for (i = 0; i < args.length; i++) args[i] = arguments[i];

			benchQueue.push(args);
			return;
		}

		benchRunning++;

		// See how many times we can get it to run for 300ms
		Collection.Function.doTime(300, fn, function(err, runs, elapsed) {

			// See how the baseline latency is like
			Blast.getEventLatencyBaseline(function(err, median) {
				asyncTest(fn, runs, median+(getFunctionOverhead(runs)*8), function asyncDone(err, result) {

					var next,
					    name;

					// Call the callback
					if (callback) {
						result.name = fn.name || '';
						callback(err, result);
					} else {
						name = fn.name || '';
						if (name) name = 'for "' + name + '" ';

						console.log('Benchmark ' + name + 'did ' + Bound.Number.humanize(result.ops) + '/s (' + Bound.Number.humanize(result.iterations) + ' iterations)');
					}

					benchRunning--;

					// Schedule a next benchmark
					if (benchRunning == 0 && benchQueue.length > 0) {

						// Get the top of the queue
						next = benchQueue.shift();

						Blast.setImmediate(function() {
							doAsyncBench.apply(null, next);
						});
					}
				});
			});
		});
	}
634234
function (callback) {
          async.parallel(
            [
              // fake db 1
              function (callback) { setTimeout(callback, 2000); },

              // fake db 2
              function (callback) { setTimeout(callback, 1000); }
            ],
            callback
          );
        }
442042
function invokeFunctions(promise) {
  var funcs = promise.funcs;

  for (var i = 0, c = funcs.length; i < c; i += 3) {
    invokeFunction(promise, funcs[i], funcs[i + promise.state]);
  }

  // Empty out this list of functions as no one function will be called
  // more than once, and we don't want to hold them in memory longer than needed
  promise.funcs.length = 0;
}
1363624
def once(func):
    """"""
    lock = threading.Lock()

    def new_func(*args, **kwargs):
        if new_func.called:
            return
        with lock:
            if new_func.called:
                return
            rv = func(*args, **kwargs)
            new_func.called = True
            return rv

    new_func = update_wrapper(new_func, func)
    new_func.called = False
    return new_func
280455
function executeWithCount(func) {
  var count = 0;
  return function () {
    for (var _len = arguments.length, args = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
      args[_key2] = arguments[_key2];
    }

    return func.call.apply(func, [this, count++].concat(args));
  };
}
647771
def _multi_call(function, contentkey, *args, **kwargs):
    '''
    
    '''
    ret = function(*args, **kwargs)
    position = ret.get('position')

    while position:
        more = function(*args, position=position, **kwargs)
        ret[contentkey].extend(more[contentkey])
        position = more.get('position')
    return ret.get(contentkey)
868241
async function asyncForEach(array, callback) {
  for (let index = 0; index < array.length; index++) {
    // eslint-disable-next-line no-await-in-loop
    await callback(array[index], index, array);
  }
}
106792
function createAsyncFunction(functionName, functionInfo) {
    return function asyncLJMFunction() {
        var userCB;
        function cb(err, res) {
            if(err) {
                console.error('Error Reported by Async Function', functionName);
            }
            
            // Create an object to be returned.
            var ljmError = res;
            var retObj = {
                'ljmError': ljmError,
            };
            if(ljmError !== 0) {
                retObj.errorInfo = modbus_map.getErrorInfo(ljmError);
            }

            // Fill the object being returned with data.
            parseAndStoreSyncFunctionArgs(functionInfo, funcArgs, retObj);

            // Execute the user's callback function.
            userCB(retObj);

            return;
        }

        // Check arg-length + 1 for the callback.
        if(arguments.length != (functionInfo.args.length + 1)) {
            var errStr = 'Invalid number of arguments.  Should be: ';
            errStr += functionInfo.args.length.toString() + '.  ';
            errStr += getFunctionArgNames(functionInfo).join(', ');
            errStr += ', ' + 'callback.';
            throw new LJMFFIError(errStr);
        // } else if(typeof(arguments[arguments.length]) !== 'function') {
        //     var errStr
        } else {
            if(typeof(arguments[functionInfo.args.length]) !== 'function') {
                userCB = function() {};
            } else {
                userCB = arguments[functionInfo.args.length];

            }

            // Create an array that will be filled with values to call the
            // LJM function with.
            var funcArgs = [];

            // Parse and fill the function arguments array with data.
            allocateAndFillSyncFunctionArgs(functionInfo, funcArgs, arguments);

            // Over-write the function callback in the arguments list.
            funcArgs[funcArgs.length] = cb;

            // Execute the asynchronous LJM function.
            var ljmFunction = liblabjack[functionName].async;
            ljmFunction.apply(this, funcArgs);

            return;
        }
    };
}
862328
def avoid_parallel_execution(func):
    
    def func_wrapper(*args, **kwargs):
        if not getattr(func, "currently_executing", False):
            func.currently_executing = True
            try:
                return func(*args, **kwargs)
            finally:
                func.currently_executing = False
        else:
            logger.verbose("Avoid parallel execution of function {}".format(func))
    return func_wrapper
1217620
async function (opt) {
		opt.create = false;

		const values = [];
		const results = await this.traverse(opt);

		for (const result  of results) {
			if (result.data[result.key] === opt.value) {
				values.push(result);
			}
		}

		return values;
	}
500293
function async(value, bool) {
   var def = promise()
   setTimeout(function() {
 	   if(!bool) def.fulfill(value)
     else def.reject('error')
   }, 10)
   return def.promise
 }
284281
function runAsync(context, func, callback)
{
  var result
    , requiresContext = isArrowFunction(func)
    ;

  if (requiresContext)
  {
    result = func.call(null, context, callback);
  }
  else
  {
    result = func.call(context, callback);
  }

  return result;
}
696384
def execute(*args, **kwargs):
    """"""
    if kwargs:
        # TODO: Remove this when pyntcontrib's execute does this
        args = list(args)
        args.extend(_kwargs_to_execute_args(kwargs))
    _execute(*args)