node. JS Asynchronous callback

Source: Internet
Author: User

Suppose A is an asynchronous function, A has a parameter A and a callback function (b), where the callback function has a return value b,a function is called a (a,function (b)), and C is a wrapper function in which the asynchronous function A is called. Then, when you want to call the C function externally, get the result B value of the A function executed asynchronously, you can add a callback function named C to C and call the method C (a,c). The above formula pseudo-code can be represented if:

function C (a,c) {

A (A,function (b) {

C (b);

});

}

function C (b) {

Console.log (b);

}

Code Description:

1.functionC (A,C): C is a callback function name for the C function.

2.A (A,function (b) {}): A is an asynchronous function where a is its argument and function (b) {} is an unnamed callback function.

3.C (b): Call C's callback function name and pass the B return value to the C function.

4.function C (b): handles the return result of the asynchronous call function.

node. JS Asynchronous callback

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.