Skip to content
BENIBIX Learn

Synchronous Code

Development🧭 Programming ParadigmsAsynchronous Code

Also known as Synchronous, Sync Code, Blocking Code

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

Think of it like

Think of it like a queue at one till. Each person waits until the one in front is done.

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.

Definition

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.

Common mistake

Doing a slow download in synchronous code inside an app's screen. The whole window freezes until it ends.

Key takeaways

  1. 1
    One at a time. In the order written.
  2. 2
    Waits block. Nothing else runs.
  3. 3
    Easy to read. Top to bottom.

Compare