Skip to content
This repository was archived by the owner on Jun 10, 2019. It is now read-only.

Extra-Tick before sync-function is called #120

@pubkey

Description

@pubkey

Source:

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions