Questions tagged [event-programming]

Event-driven programming refers to the programming technique where the flow of the program is driven by recognition and handling of events such as mouse clicks, key presses, etc.

Event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions (mouse clicks, key presses) or messages from other programs or threads.

Event-driven programming can also be defined as an application architecture technique in which the application has a main loop which is clearly divided down to two sections: the first is event selection (or event detection), and the second is event handling. In embedded systems the same may be achieved using interrupts instead of a constantly running main loop; in that case the former portion of the architecture resides completely in hardware.

Event-driven programs can be written in any language, although the task is easier in languages that provide high-level abstractions, such as closures. Some integrated development environments provide code generation assistants that automate the most repetitive tasks required for event handling.

(Source: Wikipedia).

230 questions
139
votes
11 answers

How does an event listener work?

During one of my lectures today about Unity, we discussed updating our player position by checking every frame if the user has a button pushed down. Someone said this was inefficient and we should use an event listener instead. My question is,…
Gary Holiday
  • 1,181
67
votes
5 answers

When should I use event-based programming?

I have been passing callbacks or just triggering the functions from other function in my programs to make things happen once tasks complete. When something finishes, I trigger the function directly: var ground = 'clean'; function shovelSnow(){ …
J.Todd
  • 3,823
18
votes
5 answers

Is event chaining considered good practice?

From time to time I've encountered scenarios where several complex conditions need to be met prior to triggering an event. Furthermore, most listeners also run additional checks to determine the course of action. This got me thinking whether a…
kgilden
  • 531
  • 5
  • 11
10
votes
2 answers

How to detect achievements in gaming?

I mistakenly posted this to stackoverflow and now posting here based on a suggestion in on that site ... This is a very high level conceptual question. Say in a software application I have 4 different actions, for example: Upload, Share, Comment,…
9
votes
2 answers

Should an event listener be called if attached after the event has already fired?

Should an event listener be called if it is attached after the event has already fired? What if the event will only be fired once? The first example that comes to mind is the ready event in jQuery. The following snippet, when evaluated after the…
Whymarrh
  • 159
4
votes
3 answers

Difference between event loop and system calls/interrupts

When you create programs (like a socket server) that are designed to run on an operating system, such as Ubuntu, frameworks like Qt for C++ use something called a main event loop: app = new QCoreApplication(argc, argv); int rc = app->exec() Now…
3
votes
2 answers

Where should event debouncing be done, in the emitter or consumer?

Where does it make the most sense to debounce events? Consider the resize event of an internet browser. The browser can fire a myriad of resize events as a user clicks and drags to resize a browser window. However, usually, you end up debouncing…
zero298
  • 225
  • 1
  • 9
1
vote
5 answers

Should I use events in this case?

I'm creating a video player, like a custom YouTube player. All of the GUI elements (progress bar, video player, play button, ...) are different classes, but I obviously need them to communicate. When the progress bar is clicked, or the slider is…
joon
  • 113
  • 2
0
votes
1 answer

How should I keep track of an elements' state within a window/view?

I am trying to implement a view that contains many elements, whose state change depending on the actions you perform on it. I guess this is something that people often run into so I would like to know what approach works best for you. What I usually…
0
votes
2 answers

Receive events in an event-loop, single-threaded

Let's say I have a program which consists of a main event loop. The event loop should check for tasks and if one exists, it is to be processed. The user interface consists of a GUI with buttons, for each of which can be defined a callback function…
0
votes
2 answers

Deeper understanding of event loops and timers

I have a basic grasp of accepting clients without creating a thread for each connection using tools such as select and modern equivalents (kqueue, epoll). But where do I go from here? e.g async I/O and (periodic) timers. I could crack open the…
mds
  • 113
0
votes
2 answers

Event Driven Programming?

I have been looking into event driven programming in C and the language doesn't seem to have support for it. This has led me to wonder about the nature of event driven programming. Is it correct to say that an event handler basically spawns a thread…
stmfunk
  • 175
  • 2
  • 6
0
votes
3 answers

Is it okay to call functions when event occurs, or after that?

So I was not sure how to structure this title, feel free to edit it. My question is: When I have a Game Loop, I have 3 main blocks. Handle Events, Update game state, and draw. Let's say for example I check for keyboard/mouse events, and I want to…
dragons
  • 103
-1
votes
2 answers

in an event driven architecture, should all stream consumers receive every message published to the stream?

I'm tinkering with the new streaming plugin provided with RabbitMQ, and researching how to implement event driven architectures in general. I noticed in the default configuration (maybe I have it configured wrong) if I have one app consisting of two…
alilland
  • 289