初始化
This commit is contained in:
36
uni_modules/UniDevTools/node_modules/licia/waitUntil.js
generated
vendored
Normal file
36
uni_modules/UniDevTools/node_modules/licia/waitUntil.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
var now = require('./now');
|
||||
exports = function(condition) {
|
||||
var timeout =
|
||||
arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
||||
var interval =
|
||||
arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 250;
|
||||
function evalCondition() {
|
||||
return new Promise(function(resolve, reject) {
|
||||
try {
|
||||
resolve(condition());
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
return new Promise(function(resolve, reject) {
|
||||
var startTime = now();
|
||||
var pollCondition = function() {
|
||||
evalCondition().then(function(val) {
|
||||
var elapsed = now() - startTime;
|
||||
if (val) {
|
||||
resolve(val);
|
||||
} else if (timeout && elapsed >= timeout) {
|
||||
reject(
|
||||
Error('Wait timed out after '.concat(timeout, ' ms'))
|
||||
);
|
||||
} else {
|
||||
setTimeout(pollCondition, interval);
|
||||
}
|
||||
}, reject);
|
||||
};
|
||||
pollCondition();
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = exports;
|
||||
Reference in New Issue
Block a user