coTest.js 608 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * Created by benzhan on 15/8/20.
  3. */
  4. var co = require('co');
  5. var fs = require('fs');
  6. var Q = require('q');
  7. //var readdir = Q.nbind(fs.readdir)
  8. //co(function* () {
  9. // console.log(1);
  10. // var files = yield readdir('./');
  11. // console.log(files);
  12. // console.log(2);
  13. // return files;
  14. //}).then(console.log, console.error);
  15. var compute = function* (a, b) {
  16. var foo = a + b;
  17. yield console.log(foo);
  18. foo = foo + 5;
  19. yield console.log(foo);
  20. };
  21. var generator = compute(4, 2);
  22. generator.next(3, 8);
  23. generator.next("Hello world!"); // Hello world!
  24. var i = 1;
  25. console.log('i:' + i);