It`s slightly difficult to ask good questions if you knowledge a small, but I try to be best. My apologies if I mislead you.
So, I try to understand generally differences on event-based and parallel-based style. I read question about How to articulate the difference between asynchronous and parallel programming?, but anyway I confused.
Why it is very important to me:
fork() or its analog is a heavy weapon, as I know. It copy data (or share it, but in some case it worst), spawn new process (which may die or something bad happened), have huge problem to return data back to "parent" process and so on. Yes, at CPAN is exists bunch of good designed modules to wrap this problem and give to me smooth interface, but any way fork-style have some overhead.
In this case, as I see, I need follow to simply rule - "if you CAN solve you problem without fork() or Parallel::* you MUST NOT use it, you SHOULD use event-based solutions instead"
May be I totally wrong there too?
Is it right I see:
event-based style should be chosen if we are have IO-operations or something, using external (to my program) event, like signal, or file changed, or data in pipe and so on
parallel-based style must be chosen if we are have only internal (to the program) "event", like subroutine finish calculated.
In other word, if I always have subroutine or class method/function and I know it`s have some latency "inside" ( because a lot of calculation or its waiting something - the are no differences ) - I must use parallel-based style only. And no way to use it event-based style, it be worked continuously, because this code will block main program and will block "event flow".
And I may use event-based style only if I write subroutine or class method/function with "waiting latency inside", when it calling something outside main program.
Is it correctly?
EDIT:
this is pseudo-code for clearance
# we are CANT re-write this methods, but we are known it`s have latency
sub method_with_latency_as_blackbox1{...};
sub method_with_latency_as_blackbox2{...};
my @in_data = (2,3,5);
my @out_data;
# we are need to run this for each item in @in_data array, somehow
# and there we are CAN re-write code to speed up it
# by somehow "separating" all block execution for each item
# and not method_1* from method_2* - it`s impossible because it related
foreach my $ent ( @in_data ){
my $res1 = method_with_latency_as_blackbox1( $ent );
my $res2 = method_with_latency_as_blackbox2( $ent, $res1 ); # yes, it related
push @out_data, $res2; # we are not care about result position
}
how I can use AnyEvent or Coro to speed up code like this one?