6.7.0 - Alpha6 - Fine tuning
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
(function() {
|
||||
(function () {
|
||||
function setReadonlyAttribute(obj, att, value, enumerable) {
|
||||
enumerable = (enumerable === undefined) ? true : enumerable
|
||||
enumerable = (enumerable === undefined) ? true : enumerable;
|
||||
Object.defineProperty(obj, att, {
|
||||
value,
|
||||
writable: false,
|
||||
configurable: true,
|
||||
enumerable,
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function copyInputStream(inputstream, outputstream) {
|
||||
@@ -17,40 +17,43 @@
|
||||
}
|
||||
outputstream.flush();
|
||||
}
|
||||
//此对象用于确保在多线程执行异步任务时主线程不会因空闲而停止
|
||||
|
||||
// 此对象用于确保在多线程执行异步任务时主线程不会因空闲而停止
|
||||
function AsyncThreadLock() {
|
||||
this.lock = threads.lock();
|
||||
this.tasks = 0;
|
||||
this.intervalId = null;
|
||||
}
|
||||
setReadonlyAttribute(AsyncThreadLock, 'teeFn', function() {
|
||||
|
||||
setReadonlyAttribute(AsyncThreadLock, 'teeFn', function () {
|
||||
this.intervalId = setInterval(() => {
|
||||
this.lock.lock();
|
||||
if (this.tasks === 0) {
|
||||
clearInterval(this.intervalId)
|
||||
clearInterval(this.intervalId);
|
||||
this.intervalId = null;
|
||||
}
|
||||
this.lock.unlock();
|
||||
}, 200)
|
||||
}, false)
|
||||
}, 200);
|
||||
}, false);
|
||||
|
||||
AsyncThreadLock.prototype.addTask = function() {
|
||||
AsyncThreadLock.prototype.addTask = function () {
|
||||
this.lock.lock();
|
||||
this.tasks++;
|
||||
if (this.intervalId === null) {
|
||||
AsyncThreadLock.teeFn.call(this)
|
||||
AsyncThreadLock.teeFn.call(this);
|
||||
}
|
||||
this.lock.unlock();
|
||||
}
|
||||
AsyncThreadLock.prototype.removeTask = function() {
|
||||
};
|
||||
|
||||
AsyncThreadLock.prototype.removeTask = function () {
|
||||
this.lock.lock();
|
||||
this.tasks--;
|
||||
this.lock.unlock();
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
setReadonlyAttribute,
|
||||
copyInputStream,
|
||||
AsyncThreadLock,
|
||||
}
|
||||
})()
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user