examples/waitfor-demo.js
function handler(req,res){  
    try{
      res.writeHead(200, {'Content-Type': 'text/html'});
      var start = new Date().getTime();
      //console.log(start);

      //read css, wait.for syntax:
      var css = wait.for(fs.readFile,'style.css','utf8');

      //read post, fancy syntax:
      var content = wait.for(fs.readFile,'blogPost.txt','utf8');

      //compose  template, fancy syntax, as parameter:
      var template = composeTemplate ( css, wait.for(fs.readFile,'blogTemplate.html','utf8') );

      console.log('about to call hardToGetData...');

      //call async, wait.for syntax, in a expression
      var hardToGetData = "\n" + start.toString().substr(-5) +"<br>" + ( wait.for(longAsyncFn,'some data') );

      console.log('hardToGetData=',hardToGetData);
      
      var end = new Date().getTime();

      hardToGetData += ', after '+(end-start)+' ms<br>';
      hardToGetData += end.toString().substr(-5);

      res.end( applyTemplate(template, formatPost ( content + hardToGetData) ) );

    }
    catch(err){
      res.end('ERROR: '+err.message);
    }
  }
function handler(req,res){  
    try{
      res.writeHead(200, {'Content-Type': 'text/html'});
      var start = new Date().getTime();
      //console.log(start);

      //read css, wait.for syntax:
      var css = wait.for(fs.readFile,'style.css','utf8');

      //read post, fancy syntax:
      var content = wait.for(fs.readFile,'blogPost.txt','utf8');

      //compose  template, fancy syntax, as parameter:
      var template = composeTemplate ( css, wait.for(fs.readFile,'blogTemplate.html','utf8') );

      console.log('about to call hardToGetData...');

      //call async, wait.for syntax, in a expression
      var hardToGetData = "\n" + start.toString().substr(-5) +"<br>" + ( wait.for(longAsyncFn,'some data') );

      console.log('hardToGetData=',hardToGetData);
      
      var end = new Date().getTime();

      hardToGetData += ', after '+(end-start)+' ms<br>';
      hardToGetData += end.toString().substr(-5);

      res.end( applyTemplate(template, formatPost ( content + hardToGetData) ) );

    }
    catch(err){
      res.end('ERROR: '+err.message);
    }
  }
function handler ( req , res ) { try { res . writeHead ( 200 , { 'Content-Type' : 'text/html' } ) ; var start = new Date ( ) . getTime ( ) ; //console.log(start); //read css, wait.for syntax: var css = wait . for ( fs . readFile , 'style.css' , 'utf8' ) ; //read post, fancy syntax: var content = wait . for ( fs . readFile , 'blogPost.txt' , 'utf8' ) ; //compose  template, fancy syntax, as parameter: var template = composeTemplate ( css , wait . for ( fs . readFile , 'blogTemplate.html' , 'utf8' ) ) ; console . log ( 'about to call hardToGetData...' ) ; //call async, wait.for syntax, in a expression var hardToGetData = "\n" + start . toString ( ) . substr ( - 5 ) + "<br>" + ( wait . for ( longAsyncFn , 'some data' ) ) ; console . log ( 'hardToGetData=' , hardToGetData ) ; var end = new Date ( ) . getTime ( ) ; hardToGetData += ', after ' + ( end - start ) + ' ms<br>' ; hardToGetData += end . toString ( ) . substr ( - 5 ) ; res . end ( applyTemplate ( template , formatPost ( content + hardToGetData ) ) ) ; } catch ( err ) { res . end ( 'ERROR: ' + err . message ) ; } }
handle request in a fiber
handle request in a fiber