Я с Node.js и TypeScript, и я использую async/await.
Это мой тестовый пример:
async function doSomethingInSeries() {
    const res1 = await callApi();
    const res2 = await persistInDB(res1);
    const res3 = await doHeavyComputation(res1);
    return 'simle';
}
Я хотел бы установить тайм-аут для общей функции. То есть если res1 занимает 2 секунды, res2 занимает 0,5 секунды, res3 занимает 5 секунд. Я хотел бы иметь тайм-аут, который через 3 секунды позволит мне сделать ошибку.
При обычном вызове setTimeout проблема возникает из-за потери области:
async function doSomethingInSeries() {
    const timerId = setTimeout(function() {
        throw new Error('timeout');
    });
    const res1 = await callApi();
    const res2 = await persistInDB(res1);
    const res3 = await doHeavyComputation(res1);
    clearTimeout(timerId);
    return 'simle';
}
И я не могу поймать его с помощью обычного Promise.catch:
doSomethingInSeries().catch(function(err) {
    // errors in res1, res2, res3 will be catched here
    // but the setTimeout thing is not!!
});
Любые идеи о том, как разрешить?