Skip to content

.each() synchronization question #513

@ericlu88

Description

@ericlu88

We encountered the following synchronization problem while using .each(). We couldn't figure out if it is intentionally design like this or a bug based on the documentation, so would like to get any insight from you guys:

// Expect: 1 2 3 4 5
// Actual: 1 3 4 5 2
console.log(1);
Promise.resolve([3,4,5])
    .each(function(v) {
        console.log(v);
    });
console.log(2);

It seems like the function get executed synchronously. The same problem happens to .filter() function too. In the contrary , the following snippet get executed expectedly:

// Expect: 1 2 [3 4 5]
// Actual: 1 2 [3 4 5]
console.log(1);
Promise.resolve([3,4,5])
    .then(function(v) {
        console.log(v);
    });
console.log(2);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions