None.js third-Step callback function "block code-non-blocking code"

Source: Internet
Author: User

Blocking Code Instances
var fs = require("fs");  // 导入文件系统 file systemvar data = fs.readFileSync(‘input.txt‘);   // 阻塞方式console.log(data.toString());  // 将文件解析为字符串,直接打印data会是code码的;console.log(data);console.log("程度执行结束");
    • Print out
    input.txt内的文本信息    程序执行结束
Non-blocking instances
var fs = require("fs");  // 导入文件系统 file systemvar data = fs.readFile(‘inputAnyc.txt‘, function (err, data) {    if (err) {        return console.error(err);    } else {        console.log(data.toString());    }});console.log("程度执行结束");
    • Print out
    程序执行结束    inputAnyc.txt内的文本信息

None.js third-Step callback function "block code-non-blocking code"

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.