Skip to content

nextTick should return a Promise to support ES8's async/await #7497

@neumannjan

Description

@neumannjan

What problem does this feature solve?

There may be situations in which you have to use multiple nextTick calls in a single function. In this case, using ES8's async/await functionality is very useful, as it can prevent overly nested, unreadable code.

Right now, I have to use either this:

async myMethod() {

    // code before first nextTick call

    await new Promise(resolve => this.$nextTick(resolve));

    // code before second nextTick call

    await new Promise(resolve => this.$nextTick(resolve)); // ugly :(

    // code after
}

Or this:

myMethod() {

    // code before first nextTick call

    this.$nextTick(() => {
        // code before second nextTick call

        this.$nextTick(() => { // ugly nesting :(
            // code after
        });
    });
}

What does the proposed API look like?

nextTick should return a Promise. It may also take a closure as a parameter for compatibility reasons.

You could then use all three variants:

    this.$nextTick(() => /* my code after */);
    this.$nextTick().then(() => /* my code after */);
    await this.$nextTick();
    /* my code after*/

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