Skip to content

实现一个async函数 #33

Description

@Rain120

题目

function getNum(num) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(num + 1);
        }, 1000);
    });
}

function asyncToGenerator(generatorFunction) {
    // ...
}

let func = function* () {
    let f1 = yield getNum(1);
    let f2 = yield getNum(f1);
    console.log(f2);
};
asyncToGenerator(func)(); // 3

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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