Skip to content
BENIBIX Learn

Synchronous vs Asynchronous Code

Synchronous code waits for each line to finish before the next one starts. Asynchronous code starts a slow task, moves on, and handles the result when it arrives.

Development🧭 Programming Paradigms

Synchronous Code

Code that runs one line at a time. Each line waits for the last to finish.

Synchronous code runs one line at a time. Each line waits for the one before it to finish. If a line asks for a file or a web page, the whole program stops and waits. This is easy to read, because things happen in the order they are written. It becomes a problem when a wait is long. A screen can freeze, or a server can stop answering other people.

Example
Jack's script downloads 10 pictures one after another. Each takes 1 second, so the script takes 10 seconds.
Why it matters
Most code you write runs this way. Knowing where it waits shows you where it gets slow.
Full entry
Development🧭 Programming Paradigms

Asynchronous Code

Code that starts a slow task and keeps going. It handles the result later.

Asynchronous code starts a slow task and moves on without waiting for it. When the task is done, the program comes back to handle the result. Slow tasks are things like downloads, database calls and timers. This keeps a screen working and lets a server serve many people at once. Callbacks, promises and async/await are the tools for writing it.

Example
Jack's new script starts all 10 picture downloads at once. They finish together in about 1 second instead of 10.
Why it matters
Every web page and most servers depend on it. Without it, one slow request would stop everything.
Full entry

In one line

Synchronous Code
Code that runs one line at a time. Each line waits for the last to finish.
Asynchronous Code
Code that starts a slow task and keeps going. It handles the result later.