gulpjs / undertaker

Task registry that allows composition through series/parallel methods.
MIT License
200 stars 31 forks source link

settle not working with es2015 async functions #78

Closed xmlking closed 7 years ago

xmlking commented 7 years ago

When async function throw Error, process terminated with node errors. was expecting it will settle and error will be available in callback.

import * as Undertaker from 'undertaker';
process.env.UNDERTAKER_SETTLE = 'true'

const tasker = new Undertaker();
console.log(tasker._settle)
function delay(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
tasker.task('test1', async () => {
    await delay(1000);
    console.log('in test1 ...');
    return 1;
});
tasker.task('test2', async () => {
    console.log('in test2 ...');
    // return 2;
    throw new Error('test6 error')
});
tasker.task('test3', async () => {
    await delay(2000);
    console.log('in test3 ...');
    return 3;
});

tasker.task('test4', async () => {
    await delay(1000);
    console.log('in test4 ...');
    return 4;
});
tasker.task('test5', async () => {
    console.log('in test5 ...');
    return 5;
});
tasker.task('test6', async () => {
    await delay(1000);
    console.log('in test6 ...');
    return 6;
});

tasker.task('ser', tasker.series('test1', 'test2'));
tasker.task('par', tasker.parallel( 'test3', 'test4', 'test5'));
tasker.task('serpar', tasker.series('ser', 'par', 'test6'));
tasker.task('serpar1', tasker.series(tasker.series('test1', 'test2'), tasker.parallel('test3', 'test4', 'test5'), 'test6'));
tasker.task('serpar2', tasker.parallel(tasker.series('test1', 'test2'), tasker.parallel('test3', 'test4', 'test5'),'test6'));

(async () => {
    try {
        // let tree = tasker.tree({deep: true});
        // console.log('tree', tree);

        /** case 1 **/
        tasker.task('serpar1')((err, res) => {
            if(err) {
                console.log('final error', err)
            }
            console.log('res', res);
            console.log('lastRun for test3', tasker.lastRun('test6'))
        });

    } catch (err) {
        console.log('Error:::',err)
    }
})();

Output

 ts-node src/run2.ts 
true
in test1 ...
in test2 ...
(node:13530) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: Uncaught, unspecified "error" event. ([object Object])
(node:13530) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
phated commented 7 years ago

There's no attempt to support what you are doing.