You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
459 B
25 lines
459 B
'use strict';
|
|
|
|
const Promise = require('../../promise');
|
|
|
|
function ResourceLock(resource) {
|
|
this.resource = resource;
|
|
this.previous = Promise.resolve(resource);
|
|
}
|
|
|
|
ResourceLock.prototype.unwrap = function() {
|
|
return this.resource;
|
|
};
|
|
|
|
ResourceLock.prototype.lock = function() {
|
|
const lock = this.previous;
|
|
let resolve;
|
|
|
|
this.previous = new Promise(r => {
|
|
resolve = r;
|
|
});
|
|
|
|
return lock.disposer(resolve);
|
|
};
|
|
|
|
module.exports = ResourceLock;
|
|
|