async wrapCall(fun) {
const unlock = this.lock();
let ret;
try {
console.log('wrapCall() ' + this._queueCounter);
ret = await fun();
} catch (err) {
// not sucessfull -> unlock before throwing
unlock();
throw err;
}
// sucessfull -> unlock before return
unlock();
return ret;
},
Is transpiled to:
wrapCall: function wrapCall(fun) {
var unlock,
ret,
_this3 = this;
return Promise.resolve().then(function () {
unlock = _this3.lock();
ret = void 0;
return Promise.resolve().then(function () {
console.log('wrapCall() ' + _this3._queueCounter);
return fun();
}).then(function (_resp) {
ret = _resp;
}).catch(function (err) {
// not sucessfull -> unlock before throwing
unlock();
throw err;
});
}).then(function () {
// sucessfull -> unlock before return
unlock();
return ret;
});
}
The problem here is that this.lock(); is called after the next tick instead of instantly.
This creates a different side-effect than expected.
Since the lock-call is synchronous it should transpile to something like:
wrapCall: function wrapCall(fun) {
var unlock,
ret,
_this3 = this;
unlock = _this3.lock();
return Promise.resolve().then(function () {
// etc...
```js
Source:
Is transpiled to:
The problem here is that
this.lock();
is called after the next tick instead of instantly. This creates a different side-effect than expected. Since the lock-call is synchronous it should transpile to something like: