zoukankan      html  css  js  c++  java
  • async Make errors in callbacks throw globally

    https://github.com/caolan/async/pull/1408

    let see an example:

    async.waterfall([
        function (cb) {
            const firstName = 'leeho';
            const email = '11';
            model.User.create({firstName, email})
                .then(instance => {
                    console.log('one')
                    cb(null, instance);
                }).catch(cb);
        },
        function (instance, cb) {
            // try {
            //     model.User.update({firstName: instance.firstName, lastName: balabala}, {where: {firstName: firstName}})
            //         .catch(cb)
            // } catch (e) {
            //     cb(e)
            // }
            model.User.update({firstName: instance.firstName, lastName: balabala}, {where: {firstName: firstName}})   //balabala is not defined
                .catch(cb)
            
        }
    ], function (err, result) {
        if (err) console.log('result err', err);
        console.log(result);
    })

    balabala is not defined .. and the async will throw error globally.

    async waterfall source code:

    export default  function(tasks, callback) {
        callback = once(callback || noop);
        if (!Array.isArray(tasks)) return callback(new Error('First argument to waterfall must be an array of functions'));
        if (!tasks.length) return callback();
        var taskIndex = 0;
    
        function nextTask(args) {
            var task = wrapAsync(tasks[taskIndex++]);
            task(...args, onlyOnce(next));
        }
    
        function next(err, ...args) {
            if (err === false) return
            if (err || taskIndex === tasks.length) {
                return callback(err, ...args);
            }
            nextTask(args);
        }
    
        nextTask([]);
    }

    the  wrapAsync function will wrap a function and return promise.the callback will be executed as part of the promise’s .then() method.This means that any error thrown from that method will be silenced, and lead to a “unhandled rejection”.the only way to handle it is use try catch?

  • 相关阅读:
    Oracle使用手册<收藏>
    Oracle 连接串方式
    通过多线程为基于 .NET 的应用程序实现响应迅速的用户
    PL/SQL三种集合类型的比较<收藏>
    关于Application.DoEvents() 避免假死<收藏>
    Inserting/Retrieving CLOB/NCLOB Data
    从procedure返回結果集<收藏>
    oracle ReadBlobs
    使用Update...returning...into为什么会出现ORA01036,ORA24369错误 <收藏>
    DevExpress document 地址
  • 原文地址:https://www.cnblogs.com/ybleeho/p/9707916.html
Copyright © 2011-2022 走看看