Changeset 20069 for docs/Perl6/Spec

Show
Ignore:
Timestamp:
03/06/08 00:01:18 (9 months ago)
Author:
buchetc
Message:

[t/spec] coro examples

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • docs/Perl6/Spec/Concurrency.pod

    r20063 r20069  
    247247=head2 Examples 
    248248 
     249=over 
     250 
     251=item Coro as function used in a builtin 
     252 
    249253  coro dbl { yield $_ * 2; yield $_; }; 
    250254  (1..4).map:{ dbl($_) } 
    251255  # should result in 2 2 6 4 
    252256 
    253  
     257=item Constant coro 
     258 
     259  coro foo { yield 42 }; 
     260  # always return 42 
     261 
     262=item Yield and return 
     263 
     264  coro foo ($x) { 
     265    yield $x; 
     266    # this point with $x bound to 10 
     267    yield $x+1; 
     268    return 5; 
     269    ... # this is never reached, I think we all agree 
     270  } 
     271 
     272=back 
    254273 
    255274=head1 Threads 
     
    257276=head2 Thread methods and attributes 
    258277 
    259 We intentionally do not list cross-machine parallelism Conc:: classes here. 
    260 Consult your local 6PAN mirror with a time machine. 
    261  
    262    use Conc::Processes; # fork() or createProcess based implementation 
    263    use Conc::Threads;   # maybe it just exports &async to override the default one, yay 
    264    use Conc::Multiplex; # this is default 
     278=over 
     279 
     280=item Create 
     281 
     282A thread will be created using the keyword C<async> followed by 
     283a codeblock being executed in this thread. 
    265284 
    266285   my $thr = async { 
     
    269288   }; 
    270289 
    271    Conc::Thread.this 
    272    Conc::Proc.this 
    273  
     290=item Self reflection 
     291 
     292   async { 
     293      say "my tid is ", +self(); 
     294   }; 
     295 
     296=item TODO 
    274297 
    275298 - numify to TIDs (as in pugs) 
     
    319342    async { $f.b } 
    320343 
     344=back 
    321345 
    322346=head2 Thread status 
     
    484508  p2(); p2(); 
    485509 
    486   coro foo { yield 42 }; 
    487  
    488510  coro foo ($x) { 
    489511    yield $x; 
     
    502524  foo(4); # and that's all she wrote 
    503525 
    504   coro foo ($x) { 
    505     yield $x; 
    506     # this point with $x bound to 10 
    507     yield $x+1; 
    508     return 5; 
    509     ... # this is never reached, I think we all agree 
    510   } 
    511  
    512526  # If you don't want your variables to get rebound, use "is copy": 
    513527  coro foo ($x is copy) {...}