Hopefully by now you have seen that Mojolicious is a great way to build your
non-blocking web (or even non-web) application.
Mojolicious come with all kinds of non-blocking functionality out of the box.
For more about that see my blog series
on the topic.
This post is an aside to show you the cool things happening in Mojolicious lately
designed to make writing non-blocking apps easier.
Mojolicious is known for fast development and clean APIs.
Mojo was that child with lots of excitement and energy, doing new and cool things,
providing new and cool functionality, and yes, changing its mind on occasion.
But Mojo is growing up and settling down a little bit.
It recently went to its first conference and professional training.
And it’s starting a family too!
Mojo is starting to feel more grown up, and grown-ups have responsibilities.
To borrow one of Perl’s catch phrases, this more mature Mojo knows that it is not
good enough anymore to just make things possible, it’s time to make them easy.
Last time, I showed you how to write non-blocking (web) applications using Mojolicious.
In those examples, each action only had to perform one non-blocking action.
In this article I’m going to take things a little further, introducing you to Mojo::IOLoop::Delay.
I will use a delay object to perform multiple simultaneous non-blocking actions and wait until they complete before moving on, all without blocking the server for other requests.
One question I often hear is “Why should I chose Mojolicious versus one of the other major Perl web frameworks?”
While I have many answers to that question, I personally believe the most important difference is that Mojolicious is designed to be non-blocking.
Many of you will have heard of Node.js.
The reason that Node is popular is that it is designed to be non-blocking.
By writing your webapp in a non-blocking style using a non-blocking framework, you can often build a faster and smarter application, requiring fewer servers to handle the same amount of traffic.
Although Perl has several web frameworks, only one was written with non-blocking design in mind: Mojolicious.
To demonstrate a non-blocking application, I am going to write a simple pastebin using Mojolcious and Mango, a non-blocking MongoDB library (from the same developers as Mojo).