coTest.js 652 B

123456789101112131415161718192021222324252627282930313233
  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. console.log(23);
  21. };
  22. var generator = compute(4, 2);
  23. generator.next(3, 8);
  24. generator.next("Hello world!"); // Hello world!
  25. generator.next(3, 8);
  26. var i = 1;
  27. console.log('i:' + i);