- Architecting Angular Applications with Redux,RxJS,and NgRx
- Christoffer Noring
- 276字
- 2021-08-27 19:56:22
Asynchronous Programming
To learn what asynchronous code is, let's first cover what synchronous code is. With synchronous code, you have one statement being executed after another. The code is predictable; you know what happens and when. This is because you can read the code from top to bottom like this:
print('a')
print('b')
print('c')
// output
a, b, c
Now, with asynchronous code you lose all the nice predictability that the synchronous code offers. In fact, there is very little you know about asynchronous code other than that it finishes executing, eventually. So asynchronous, or async, code looks more like this:
asyncPrint('a')
asyncPrint('b')
asyncPrint('c')
// output
c, b, a
As you can see, the order in which a statement finishes is not determined by when a statement occurs in the code. Instead, there is a time element involved that decides when a statement has run its course.
Asynchronous code runs in an event loop. This means that async code runs in the following order:
- Run async code
- Wait for the response to be ready, then fire an interrupt
- Run the event handler
An important thing to stress here is that async code is non-blocking—other operations can take place while async code is running. Therefore, async code is a good candidate to be used when dealing with I/O, long-running tasks, and network requests.
In this chapter, we will:
- Learn what asynchronous programming is and how it differs from synchronous programming
- Explain the callback model
- Describe promises and how they completely reformed how we write asynchronous code
- Look at which other asynchronous libraries exist and in what cases they should be used
- Discover the new standard async/await
- Aptana Studio Beginner's Guide
- Mastering Machine Learning for Penetration Testing
- 光網(wǎng)絡(luò)評(píng)估及案例分析
- Django 2 by Example
- 網(wǎng)絡(luò)創(chuàng)新指數(shù)研究
- 物聯(lián)網(wǎng)+BIM:構(gòu)建數(shù)字孿生的未來
- Spring Cloud微服務(wù)架構(gòu)進(jìn)階
- 信息通信網(wǎng)絡(luò)建設(shè)安全管理概要2
- Mastering TypeScript 3
- Mastering Dart
- 網(wǎng)絡(luò)安全應(yīng)急響應(yīng)技術(shù)實(shí)戰(zhàn)指南
- INSTANT LinkedIn Customization How-to
- 5G時(shí)代的大數(shù)據(jù)技術(shù)架構(gòu)和關(guān)鍵技術(shù)詳解
- 圖解物聯(lián)網(wǎng)
- Hands-On Reactive Programming in Spring 5