4

Is "event based" the same as "asynchronous"?

3 Answers 3

10

No it doesn't imply that the events are asynchronous.

In a event driven single threaded system, you can fire events, but they are all processed serially. They may yield as part of their processing, but nothing happens concurrently, if they yield, they stop processing and have to wait until they are messaged again to start processing again.

Examples of this are Swing ( Java ), Twisted ( Python ), Node.js ( JavaScript ), EventMachine ( Ruby )

All of these examples are event driven message loops, but they are all single threaded, every event will block all subsequent events on that same thread.

In programming, asynchronous events are those occurring independently of the main program flow. Asynchronous actions are actions executed in a non-blocking scheme, allowing the main program flow to continue processing.

So just because something is event driven doesn't make it asynchronous, and just because something is asynchronous doesn't make it event driven either; much less concurrent.

2
  • I thought Node.js is in fact asynchronous.
    – nickb
    Oct 28, 2011 at 6:55
  • 1
    @nickb from the Node.js front page "Node is similar in design to and influenced by systems like Ruby's Event Machine or Python's Twisted." and "But what about multiple-processor concurrency? Aren't threads necessary to scale programs to multi-core computers? You can start new processes via child_process.fork() these other processes will be scheduled in parallel."
    – user177800
    Oct 28, 2011 at 7:00
3

They are essentially orthogonal concepts.

"event driven" essentially means that the code associated to certain function calls is bind at runtime (and can change through the execution). Who "fires" the event doesn't know what will handle it, and who handle the event is defined to respond to the event through an association defined while the program executes. Typically though function pointers, reference or pointers to object carrying virtual methods etc.)

"asynchronous" means that a program flow doesn't have to wait for a call to be executed before proceed over (mostly implemented with a call that returns immediately after delegating the execution to another thread or process)

Not all events are asynchronous (think to the windows SendMessage, respect to PostMessage), and not all asynchronous calls are necessary implemented by "events" (although the use of the event mechanism is quite common to implement asynchronous calls)

0

One meaning of asynchronous is that at a point where you emit an computation, you don't wait for an answer, but you get the answer later. The answer comes in orthogonal to you normal control flow.

One way the answer comes in is using events: They happen spontaneously in this case, without your code triggering them. In a handler you may process the result.

Whereas the computation and answer is connected by the point in control flow for synchronous mode, you have to do the connection yourself in asynchronous mode. For example by use of a sequence number or something.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.