Tuesday, February 3, 2015 [Tweets] [Favorites]

What Color Is Your Function?

Bob Nystrom (via Marco Arment):

But if you have threads (green- or OS-level), you don’t need to do that. You can just suspend the entire thread and hop straight back to the OS or event loop without having to return from all of those functions.

Go is the language that does this most beautifully in my opinion. As soon as you do any IO operation, it just parks that goroutine and resumes any other ones that aren’t blocked on IO.

If you look at the IO operations in the standard library, they seem synchronous. In other words, they just do work and then return a result when they are done. But it’s not that they’re synchronous in the sense that it would mean in JavaScript. Other Go code can run while one of these operations is pending. It’s that Go has eliminated the distinction between synchronous and asynchronous code.

2 Comments

"Go has eliminated the distinction between synchronous and asynchronous code."

Wait... Google now has a formal proof checker for all of time and space?

Why the hell aren't I notified about these things?

Every single language known to mankind blocks a thread waiting for IO, and runs other threads while it's waiting.

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment