Value and Error Sequences

If any step of a sequence is just a normal value, that value is just mapped to that step’s completion message:

  1. var sq = ASQ( 42 );
  2. sq.val( function(msg){
  3. console.log( msg ); // 42
  4. } );

If you want to make a sequence that’s automatically errored:

  1. var sq = ASQ.failed( "Oops" );
  2. ASQ()
  3. .seq( sq )
  4. .val( function(msg){
  5. // won't get here
  6. } )
  7. .or( function(err){
  8. console.log( err ); // Oops
  9. } );

You also may want to automatically create a delayed-value or a delayed-error sequence. Using the after and failAfter contrib plug-ins, this is easy:

  1. var sq1 = ASQ.after( 100, "Hello", "World" );
  2. var sq2 = ASQ.failAfter( 100, "Oops" );
  3. sq1.val( function(msg1,msg2){
  4. console.log( msg1, msg2 ); // Hello World
  5. } );
  6. sq2.or( function(err){
  7. console.log( err ); // Oops
  8. } );

You can also insert a delay in the middle of a sequence using after(..):

  1. ASQ( 42 )
  2. // insert a delay into the sequence
  3. .after( 100 )
  4. .val( function(msg){
  5. console.log( msg ); // 42
  6. } );