I am writing a verification system that performs various โchecksโ on various services, systems, databases, files, etc. A โcheckโ is general in nature and can be anything. All checks are reported in a common weather format that they skip or fail, no matter what.
This is written in a modular way OO, so that developers can simply follow the frame and write checks regardless of both. Each object contains a common reporting object, which after starting the check is simply $ self โ {'report'} โ report (params). The parameters are defined, and it is assumed that the developers report this accordingly. The reporting entity then indexes these reports. My main script loader has entries like:
my $reportingObject = new Checks::Reporting(params); my @checks; push @checks, new Checks::Check_One($reportingObject, params)); push @checks, new Checks::Check_One($reportingObject, params)); . . push @checks, new Checks::Check_N($reportingObject, params));
To start checking and complete the report after they are completed, I do:
foreach my $check (@checks) { $check->run_stuff(); } $reportingObject->finalize_report();
Now, since these checks are completely independent (do not worry about the reporting object), they can be run in parallel. As an improvement, I did:
my @threads; foreach my $check (@checks) { push @threads, async { $check->run_stuff(); } } foreach my $thread (@threads) { $thread->join; }
As I said, developers will write Checks independently of each other. Some checks are simple, while others are not. Simple checks may not have asynchronous code in them, but others may need to run asynchronously inside, for example
sub do_check { my @threads; my @list = @{$self->{'list'}}; foreach my $item (@list) { push @threads, async {
As you can see, the threading model allows me to do things in very vague terms. Each "Check" no matter what it runs independently in its own branch. If an individual developer has asynchronous material, regardless of what he has, he simply does it on his own in his thread. I need a model like this.
Unfortunately, threads are slow and inefficient. All asynchronous libraries have specific observers, such as IO, etc. I do not want anything specific. I need an event-based model that allows me to simply run asynchronous tasks, no matter what they are, and just notify when all this is done so I can move on.
Hope this explains this and you can point me in the right direction.