yunabe / tslab

Interactive JavaScript and TypeScript programming with Jupyter
Apache License 2.0
702 stars 44 forks source link

Stop waiting for the last Promise automatically #17

Closed yunabe closed 4 years ago

yunabe commented 4 years ago

In the current implementation, when we run the code below, tslab wait for the asynchronous result of hello() and shows Hello, tslab!.

function hello(): Promise<string> {
    return new Promise(done => {
        setTimeout(() => {
            done('Hello, tslab!');
        }, 100);
    });
}

hello();

After I created some notebooks (e.g. MNIST with tenworflow.js), I noticed this behavior is a little confusing because hello() shows Hello, tslab!, not Promise(...) and users misunderstand hello() returns string, not Promise<string>.

Also, Chrome dev console, which supports top-level await, shows Promise {<pending>} for hello(). Chrome dev console shows Hello, tslab! when await hello() is executed.

Thus, I think we should stop waiting for the last Promise automatically. We should support top-level awaits instead (https://github.com/yunabe/tslab/issues/16).