I found an interesting questions regarding the events in action script: is the event buffered and ordered?
Ie) In a swfloader example, I setup a timer(1 sec) to run a function, in the function I setup a listener to event INIT of the loaded swf. It depends on the network condition that whether the timer handler or the INIT event will be first executed. Imagine a case that the INIT event fired first but the handler to handle the INIT event be setup later, will the handler be invoked?
Another question, if the loaded swf fired several events very fast, will the events be kept ordered as the fire sequence?
First Question: No, if INIT event is fired first and there is no handler for that Event then that event will be lost. So the best way is to setup all the listeners first then start any loading operation.Second Question: Yes, all the events fired will be handled in the same order as they're fired.
i just wanted to add to that you can change the order in the optional params
by default first in is the first served but if you change you priorities around that can change
obj.addEventListener(type,listener,useCapture,priority,useWeakRefrence);
the higher the number is the higher it is in priority. so if i would add these events:
obj.addEventListener(type,listener1,useCapture,1,useWeakRefrence);
obj.addEventListener(type,listener2,useCapture,2,useWeakRefrence);
the second event would happen before the first one. p.s after you create the event there is no way to change the order without removing the event and adding it back in.
Related
How can I make sure I have received event (A) from an aggregate and event (B) from another aggregate before invoking a method from a third aggregate in the event handler? For example, I need productPaid event and productInStock event to buy a product?
Maybe you can do a query in the handler to some aggregate to check if the other event already happened.
Or, you need a "process manager" instead of an "event handler".
You need a state that is shared by the two event handlers, something that when you receive an event allows you to record that it happened (some storage), and when you handle an event you can check if you already received the other one.
You can think to a process manager like an aggregate that receives events instead of commands (it cannot reject them!)
I am trying to make sense of which one should be called before and which one later between wl_display_dispatch and wl_display_roundtrip. I have seen both order so wondering which one is correct.
1st order:
wl_display_get_registry(display); wl_registry_add_listener() // this call is just informational
wl_display_dispatch();
wl_display_roundtrip();
what i think : wl_display_dispatch() will read and dispatch events from display fd, whatever is sent by server but in between server might be still processing requests and for brief time fd might be empty.
wl_display_dispatch returns assuming all events are dispatched. Then wl_display_roundtrip() is called and will block until server has processed all request and put then in event queue. So after this, event queue still has pending events, but there is no call to wl_display_dispatch(). How those pending events will be dispatched ? Is that wl_display_dispatch() wait for server to process all events and then dispatch all events?
2nd order:
wl_display_get_registry(display); wl_registry_add_listener() // this call is just informational
wl_display_roundtrip();
wl_display_dispatch();
In this case, wl_display_roundtrip() wait for server to process all events and put them in event queue, So once this return we can assume all events sent from server are available in queue. Then wl_display_dispatch() is called which will dispatch all pending events.
Order 2nd looks correct and logical to me, as there is no chance of leftover pending events in queue. but I have seen Order 1st in may places including in weston client examples code so I am confused whats the correct order of calling.
It would be great if someone could clarify here.
Thanks in advance
2nd order is correct.
client can't do much without getting proxy(handle for global object). what i mean is client can send request by binding to the global object advertised by server so for this client has to block until all global object are bind in registry listener callback.
for example for client to create surface you need to bind wl_compositor interface then to shell interface to give role and then shm(for share memory) and so on.wl_display_dispatch cannot guaranty all the events are processed if your lucky it may dispatch all events too but cannot guarantee every-time. so you should use wl_display_roundtrip for registry at-least.
I'm trying to wrap my head around Laravel's queued event listener vs jobs.
To me, it seems like that both are very similar:
Both implement the ShouldQueue interface (in the case of event listener, this is an option)
Both implement the handle() and failed() (optional) methods to perform their respective tasks.
Essentially, to me, both are queued items that can be run asynchronously.
What I am able to distinguish so far is that jobs have more "advanced" features/configurations like $timeout, $tries properties and you may also delay the 'trigger' of a job (courtesy of the Illuminate\Bus\Queueable trait).
There are more I'm sure, but I'm pointing out the one that pops out to me.
So, the question is, what's the actual difference between the two and more importantly, when do you favor one over the other?
Good question, I will begin by how laravel docs explains it
Events : Laravel's events provides a simple observer implementation, allowing you to subscribe and listen for various events that occur in your application. Events serve as a great way to decouple various aspects of your application, since a single event can have multiple listeners that do not depend on each other.
Where as
Jobs : Job classes are very simple, normally containing only a handle method which is called when the job is processed by the queue.
Essentially both are pushing jobs on to queues and/or do some processing its asked to do, the main difference I would say is how they are called.
Events are on the lookout to be called where as Jobs are always explicitly called.
Power of Events is that we can register multiple listeners for a single event and the event helper will dispatch the event to all of its registered listeners without us calling them explicitly. where in case of Jobs we would have to call them each one explicitly.
In short if you have a scenario where an event would trigger multiple method calls event would help. If its a single method call Jobs are good.
Events Scenario: user signs up -> Send email, Dispatch complimentary swag, Create a subdomain for a user profile userxyz.site.com etc etc
Jobs Scenario: user signs up -> Send email.
In the exact context of the question: "Event" is a "Queued Event Listener". Every Laravel Event has a Listener bound to it (the event listener), then, when we queue that event (in the listener) it is magically a "Queued Event Listener"
Well, they are very similar, the eventlistener takes an event as a parameter in the handle method, jobs don't.
Events are good in situations where you want to decouple the triggering part from the action part. For instance when you have several modules in the project and you want one module to react on an event in another.
One limitation of events compared to jobs are job chaining. If you for instance trigger several events from a controller you can't be sure that the worker dispatches them in sequence and that the first is completed before the other is started.
In these (rare) situations I sometimes end up with (non queued) listeners that in turn dispatches (queued) jobs that do the actual work (chained or unchained).
Using event structures in LabView can get confusing, especially when mixing them with a mostly synchronous workflow. My question is, when an event structure exists in one frame of a sequence, how can I force it to ignore events (e.g. mousedown on a particular button) that were triggered while the workflow is in another frame of the sequence?
Currently, the event structures only process the events at the correct frame in the sequence, but if one was triggered while the workflow is in the previous frame, it processes those too and I want it to ignore any events that weren't triggered in the frame that the event structure exists within.
http://puu.sh/hwnoO/acdd4c011d.png
Here's part of my workflow. If the mousedown is triggered while the left part is executing, I want the event structure to ignore those events once the sequence reaches it.
Instead of placing the event structure inside your main program sequence, put it in a separate loop and have it pass the details of each event to the main sequence by means of a queue. Then you can discard the details of the events you don't want by flushing the queue at the appropriate point.
Alternatively you could use a boolean control to determine whether the event loop sends event details to the queue or discards them, and toggle the boolean with a local variable from the main sequence.
You can register for events dynamically. Registration is the point in time at which the event structure starts enqueueing events, and in your case this happens when the VI the event structure is in enters run mode (meaning it's executing or one of its callers is). You can change it so that you register using the Register for Events node and then you would only get events from that point on. When you unregister you will stop getting events.
There's a very good presentation by Jack Dunaway going into some details about events here.
You can find the code for it here.
In LabVIEW 2013 and later there are additional options for controlling the events queue, but I won't go into them here.
http://puu.sh/hwsBE/fe50dee671.png
I couldn't figure out how to flush the event queue for built-in event types like mousedown, but I managed to get around that by creating a static reference to the VI and setting the cursor to busy during the previous sequence, disabling clicking. Then when the sequence for the event structure is reached, I unset the cursor from busy, which re-enables clicking.
I've read a lot about Event::queue but I just cant get my head around it, so i have something like:
Event::listen('send_notification');
and in the controller I use
Event::fire('send_notification');
But because this takes sometime before sending the user to somewhere else, I instead want to use
Event::queue('send_notification');
To fire the event after the user has been redirected, but I don't know how.
(In the app/config/app.php i have the queue driver set to sync)
EDIT:
a small note about firing the event ,u can do all ur work just like normal ,and add all the Event::flush() as a filter ,then just call that filter through ->after() or afterFilter().
First, let me make something clear. Event::queue has nothing to do with the Queue facade and the query driver in the config. It won't enable you to fire the event after the request has happened.
But you can delay the firing of an event and therefore "prepare" it.
The usage is pretty basic. Obviously you need one or many Event::listen (well it works without them but makes no sense at all)
Event::listen('send_notification', function($text){
// send notification
});
Now we queue the event:
Event::queue('send_notification', array('Hello World'));
And finally, fire it by calling flush
Event::flush('send_notification');
In your comment you asked about flushing multiple events at once. Unfortunately that's not really possible. You have to call flush() multiple times
Event::flush('send_notification');
Event::flush('foo');
Event::flush('bar');
If you have a lot of events to flush you might need to think about your architecture and if it's possible to combine some of those into one event with multiple listeners.
Flushing the Event after redirect
Event::queue can't be used to fire an event after the request lifecycle has ended. You have to use "real" queues for that.