MCPcopy Create free account
hub / github.com/apache/cassandra-nodejs-driver / whilst

Function whilst

lib/utils.js:1010–1044  ·  view source on GitHub ↗

* @param {Function} condition * @param {Function} fn * @param {Function} callback

(condition, fn, callback)

Source from the content-addressed store, hash-verified

1008 * @param {Function} callback
1009 */
1010function whilst(condition, fn, callback) {
1011 let sync = 0;
1012 next();
1013 function next(err) {
1014 if (err) {
1015 return callback(err);
1016 }
1017 if (!condition()) {
1018 return callback();
1019 }
1020 if (sync === 0) {
1021 sync = 1;
1022 fn(function (err) {
1023 if (sync === 1) {
1024 //sync function
1025 sync = 4;
1026 }
1027 next(err);
1028 });
1029 if (sync === 1) {
1030 //async function
1031 sync = 2;
1032 }
1033 return;
1034 }
1035 if (sync === 4) {
1036 //Prevent "Maximum call stack size exceeded"
1037 return process.nextTick(function () {
1038 fn(next);
1039 });
1040 }
1041 //do a sync call as the callback is going to call on a future tick
1042 fn(next);
1043 }
1044}
1045
1046
1047/**

Callers

nothing calls this directly

Calls 1

nextFunction · 0.70

Tested by

no test coverage detected