Node. js synchronization problems

Source: Internet
Author: User

Nodejs is asynchronous, which is a bit more concurrent;

For example, if you want to access multiple URLs, you can access concurrent accesses at the same time, which is very good for multi-threaded download.


However, if the subsequent program requires the results of the previous program to continue, this problem occurs in the Multi-concurrency environment.


Async can solve this problem.


It should be noted that async can control the serial execution of functions, but the function interface must be set and callback is executed at last!


Var urlcontent = "http://bbs.chinagame.me/topic/1/1#1"; var r = require ('request'); var subject, content; var async = require ('async'); function a (callback) {req = r (urlcontent, function (a, B, c) {var body = c; var regex =/<title> (. *?) <\/Title>/gim; var title = regex.exe c (body); subject = title [1]; var regex1 =/itemprop = "text"> (.*?) <\/Div>/gim; var con = regex1.exec (body); content = con [1]; callback (null, 'two ');});} function B (callback) {console. log (subject, content); callback (null, 'B');} async. series ([a, B]);


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.