Javascript is designed for asynchronous event-loop programming and it works very well with a state machine architecture. State machines can be very theoretical but in practice many state machines are simple, application-based constructions. One such is developed in this little ebook. The goal here is to show you how you could make your own state machines. Then you can write long running tasks that play nicely with event handlers.
Readers are expected to have some experience writing Javascript as well as to have a nodding acquaintance with Node.js. Prior experience with theoretical state machines might be detrimental but, if so, you will get over it.