![]() The same happens for quit, which – as you may have understood – doesn't stop any working job, it just waits for its turn.Īnd this is exactly everything an external object will see, just these two public functions. If an event is high priority it won't be put in the back of the queue, but right at the front. ![]() Both have one optional argument, highPriority. The class is defined with two functions and empty bodies (the pass keyword is to avoid compilation error). class EventQueue:ĭef enqueue(self, '''function call''' highPriority = False): Another function to get the results, you say? We'll come to that, we don't want a publicly available function to expose that. Just one function to add an event to the queue, "enqueue", and another to stop processing and receiving events, "stop". We're not banging rocks together here!Īs for the public interface, we need to keep it really simple. ![]() Should be smart: we don't want to see any busy wait, as some other implementations out there do.Should return results when we want them, and all the results, even if our call threw an exception.That's the point: you call it from whichever thread and it works. Should be thread safe, we want it to handle all the concurrency, so we don't have to.Should be simple to use – you istantiate it and bam! It runs with no problems.We want our event queuer to have the following: the possibilities are endless.Īnd let's not forget we are talking about Python, with its reference to functions, it will be as easy as writing enqueue(someclass.somefunction), no messing around with interfaces in Java (though there's a EventQueue pre-defined in the java collection) Features This comes really handy whenever a number of long-execution functions has to be called from one important thread, such as the graphical thread, or when a common resource can be called by multiple threads which cannot block, or when a timeout handler is needed. We start asking ourselves: what's the need of an event queuer? It's going to be some code effort after all, what are its uses?Īn event queuer is basically a piece of software that receives events to be executed and – thus the term queue – executes them from the first arrived to the last, sequentially one after another.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |