Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
660 B
4
Indexable
Never
function promiseMock(input) { // Promise task
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            resolve(input)// CHANGE TO RESOLVE OR REJECT
        }, 2000)
    })
}

function promiseHandler(promise) { // handler
    if (Array.isArray(promise)) promise = Promise.all(promise);
    return promise.then(data => {
            return [data, null];
        })
        .catch(error => {
            return [null, error]
        })
}

(async function doJob() { // Execute call 
    const [output, error] = await promiseHandler(promiseMock('test'));
    console.log('output is: ', output);
    console.log('error is: ', error);
})()