What Happens When?

When we talk about running something “later,” it exposes the ugly truth that the world doesn’t stop changing just because your code is running. Computers can do more than one thing at once, and are doing that all the time. But most code isn’t written that way.

Think about some of the plugins we’ve looked at so far. What would happen if, right in the middle of running that piece of code, another player typed the same command and that same code started running from the top?

Take a look at the figure here. Each arrow and code snippet represents a set of instructions that the computer is running at the same time. We call each separate set a thread—kind of like the thread of a subplot in a novel, or the thread of one conversation ...

Get Learn to Program with Minecraft Plugins, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.