Imported Upstream version 3.3.3
[debian/amanda] / perl / Amanda / MainLoop.pod
index a752b608052c1981d68fddb8cb5ea999eb80dca4..cae73ff36b84a5cf74e73c490a97f7797c1a711c 100644 (file)
@@ -1,9 +1,10 @@
 /*
- * Copyright (c) 2009, 2010 Zmanda, Inc.  All Rights Reserved.
+ * Copyright (c) 2009-2012 Zmanda, Inc.  All Rights Reserved.
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 as published
- * by the Free Software Foundation.
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful, but
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
@@ -347,7 +348,7 @@ first step defined will be called automatically.
        my ($hostname, $port, $data, $sendfile_cb) = @_;
        my ($addr, $socket); # shared lexical variables
        my $steps = define_steps
-               cb => \$sendfile_cb;
+               cb_ref => \$sendfile_cb;
        step lookup_addr => sub {
            return async_gethostbyname(hostname => $hostname,
                                ghbn_cb => $steps->{'got_addr'});
@@ -400,7 +401,7 @@ achieve this for all callbacks, add C<< immediate => 1 >> to the C<define_steps>
 invocation:
 
     my $steps = define_steps
-           cb => $finished_cb,
+           cb_ref => \$finished_cb,
            immediate => 1;
 
 To do the same for a single step, add the same keyword to the C<step> invocation:
@@ -408,6 +409,13 @@ To do the same for a single step, add the same keyword to the C<step> invocation
     step immediate => 1,
         connect => sub { .. };
 
+In some case, you want to execute some code when the step finish, it can
+be done by defining a finalize code in define_steps:
+
+    my $steps = define_steps
+           cb_ref => \$finished_cb,
+           finalize => sub { .. };
+
 =head2 JOINING ASYNCHRONOUS "THREADS"
 
 With slow operations, it is often useful to perform multiple operations
@@ -419,7 +427,7 @@ commands simultaneously and capture their output:
        my $running_commands = 0;
        my ($result1, $result2);
        my $steps = define_steps
-           cb_ref => $finished_cb;
+           cb_ref => \$finished_cb;
        step start => sub {
            $running_commands++;
            run_command($command1,
@@ -428,15 +436,15 @@ commands simultaneously and capture their output:
            run_command($command2,
                run_cb => $steps->{'command2_done'});
        };
-       step command1_done {
+       step command1_done => sub {
            $result1 = $_[0];
            $steps->{'maybe_done'}->();
        };
-       step command2_done {
+       step command2_done => sub {
            $result2 = $_[0];
            $steps->{'maybe_done'}->();
        };
-       step maybe_done {
+       step maybe_done => sub {
            return if --$running_commands; # not done yet
            $finished_cb->($result1, $result2);
        };