Angular / TypeScript - Call a function after another one has been completed

后端 未结 3 1164
别那么骄傲
别那么骄傲 2020-12-24 08:35

I would like to call f2 after f1 has been completed. f1 function can be synchronous or asynchronous.

3条回答
  •  一个人的身影
    2020-12-24 08:56

    Just remove the timeout

    function f1() {
        return new Promise((resolve, reject) => {
            console.log('i am first');
            resolve();
        });
    }
    
    function f2() {
        console.log('i am second');
    }
    
    f1().then(f2);
    

提交回复
热议问题