- PHP Reactive Programming
- Martin Sikora
- 270字
- 2021-07-09 19:06:15
Asynchronous programming
The term asynchronous programming is very common in languages such as JavaScript. A very general definition is that, in asynchronous programming, we're executing code in a different order than it was defined. This is typical for any event based application.
For example, in JavaScript, we first define an event listener with its handler, which is executed some time later, when an appropriate event occurs.
In PHP, this could be, for example, a web application that needs to send an e-mail when we create a new blog article. Just, instead of lines of code, we're considering tasks. The following figure demonstrates an asynchronously triggered event:

While the web application was saving an article (processing a task), it triggered an event that sent an e-mail and then carried on with the original task. The event handler had to be defined somewhere before we started this task.
Asynchronous versus parallel programming
A very common misconception is that asynchronous and parallel programming are the same, or that one is an implication of the other. This is very common in JavaScript where, from the user's perspective, it looks like things are running in parallel.
This isn't true, but many programming languages (in fact, just their interpreters), create the illusion of running in parallel while they're still sequential. They appear to be parallel due to it's event-based nature (JavaScript), or because of their interpreter internals.
For example, Python simulates threads by switching the execution context between different parts of the application. The Python interpreter is still single threaded and executes instructions sequentially, but creates the illusion of running code in parallel.
- Flask Web全棧開發(fā)實戰(zhàn)
- 自然語言處理實戰(zhàn):預訓練模型應用及其產(chǎn)品化
- JavaScript+jQuery開發(fā)實戰(zhàn)
- Microsoft Dynamics GP 2013 Reporting, Second Edition
- Mastering Rust
- 劍指MySQL:架構(gòu)、調(diào)優(yōu)與運維
- bbPress Complete
- 蘋果的產(chǎn)品設計之道:創(chuàng)建優(yōu)秀產(chǎn)品、服務和用戶體驗的七個原則
- LabVIEW虛擬儀器入門與測控應用100例
- Getting Started with Nano Server
- Learning VMware vSphere
- OpenCV 3.0 Computer Vision with Java
- 計算機系統(tǒng)解密:從理解計算機到編寫高效代碼
- Java 11 and 12:New Features
- C語言程序設計