MCPcopy Create free account
hub / github.com/PrairieLearn/PrairieLearn / _insert

Function _insert

public/javascripts/async.js:860–891  ·  view source on GitHub ↗
(q, data, pos, callback)

Source from the content-addressed store, hash-verified

858 throw new Error('Concurrency must not be zero');
859 }
860 function _insert(q, data, pos, callback) {
861 if (callback != null && typeof callback !== "function") {
862 throw new Error("task callback must be a function");
863 }
864 q.started = true;
865 if (!_isArray(data)) {
866 data = [data];
867 }
868 if(data.length === 0 && q.idle()) {
869 // call drain immediately if there are no tasks
870 return async.setImmediate(function() {
871 q.drain();
872 });
873 }
874 _arrayEach(data, function(task) {
875 var item = {
876 data: task,
877 callback: callback || noop
878 };
879
880 if (pos) {
881 q.tasks.unshift(item);
882 } else {
883 q.tasks.push(item);
884 }
885
886 if (q.tasks.length === q.concurrency) {
887 q.saturated();
888 }
889 });
890 async.setImmediate(q.process);
891 }
892 function _next(q, tasks) {
893 return function(){
894 workers -= 1;

Callers 2

_queueFunction · 0.85
async.jsFile · 0.85

Calls 2

_arrayEachFunction · 0.85
_binarySearchFunction · 0.85

Tested by

no test coverage detected