source: doc/papers/concurrency/examples/Format.js@ 314c9d8

Last change on this file since 314c9d8 was 2aab69b, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

files added to concurrency paper

  • Property mode set to 100644
File size: 909 bytes
RevLine 
[2aab69b]1function * Format() {
2 var g, b;
3 fini: while ( true ) {
4 for ( g = 0; g < 5; g += 1 ) { // groups of 5 blocks
5 for ( b = 0; b < 4; b += 1 ) { // blocks of 4 characters
6 while ( true ) {
7 ch = (yield) // receive from send
8 if ( ch == '\0' ) break fini;
9 if ( '\n' != ch ) break
10 }
11 process.stdout.write( ch ) // receive from send
12 }
13 process.stdout.write( ' ' ) // block separator
14 }
15 process.stdout.write( '\n' ) // group separator
16 }
17 if ( g != 0 || b != 0 ) process.stdout.write( '\n' )
18}
19
20var input = "abcdefghijklmnop\nqrstuvwx\nyzxxxxxxxxxxxxx"
21
22fmt = Format()
23fmt.next() // prime generator
24for ( var i = 0; i < input.length; i += 1 ) {
25 fmt.next( input[i] ); // send to yield
26}
27fmt.next( '\0' ); // EOF
28
29// Local Variables: //
30// comment-column: 56 //
31// tab-width: 4 //
32// compile-command: "node Format.js" //
33// End: //
Note: See TracBrowser for help on using the repository browser.