zoukankan      html  css  js  c++  java
  • Callback in NodeJS Anny

    Refer to:

    http://tech.richardrodger.com/2011/04/21/node-js-%E2%80%93-how-to-write-a-for-loop-with-callbacks/

    http://stackoverflow.com/questions/6789050/node-js-callback-not-working

    Let’s also say you have a magical upload function that can do the upload:

    upload('myfile.ext', function(err){
      if( err ) {
        console.log('yeah, that upload didn't work: '+err)
      }
    })
    

    This upload function uses the callback pattern you’d expect from Node. You give it the name of the file you want to upload and then it goes off and does its thing. After while, when it is finished, it calls you back, by calling your callback function. It passes in one argument, an err object. The Node convention is that the first parameter to a callback is an object that describes any errors that happened. If this object is null, then everything was OK. If not, then the object contains a description of the error. This could be a string, or a more complex object.

    Node is asynchronous. The upload function will return before it even starts the upload.

  • 相关阅读:
    Springboot(一)springboot简介与入门程序
    Java基础(二)流程语句与数组
    Java基础(一)基础常识
    Kubernetes介绍
    K8s 存储
    Kubernetes 集群组件
    Kubernetes 设计理念
    Kubernetes 部署与实战
    容器技术与资源隔离
    Docker 网络配置
  • 原文地址:https://www.cnblogs.com/limei/p/2145957.html
Copyright © 2011-2022 走看看