generatorWriteLogDuringGeneratorExecution.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. var log;
  6. if ( typeof telemetryLog === 'undefined' ) {
  7. log = function(msg, shouldWrite) {
  8. if (shouldWrite) {
  9. WScript.Echo(msg);
  10. }
  11. };
  12. }
  13. else {
  14. log = telemetryLog;
  15. }
  16. var writeTTDLog;
  17. if (typeof emitTTDLog === 'undefined') {
  18. writeTTDLog = function (uri) {
  19. // no-op
  20. };
  21. }
  22. else {
  23. writeTTDLog = emitTTDLog;
  24. }
  25. /////////////////
  26. function* testGenerator() {
  27. var i = 0;
  28. writeTTDLog(ttdLogURI);
  29. yield i++;
  30. writeTTDLog(ttdLogURI);
  31. yield i++;
  32. writeTTDLog(ttdLogURI);
  33. yield i++;
  34. writeTTDLog(ttdLogURI);
  35. yield i++;
  36. writeTTDLog(ttdLogURI);
  37. }
  38. var gen = testGenerator();
  39. function yieldOne() {
  40. var v1 = gen.next();
  41. log(`gen.next() = {value: ${v1.value}, done: ${v1.done}}`, true);
  42. }
  43. WScript.SetTimeout(() => {
  44. yieldOne();
  45. }, 20);
  46. WScript.SetTimeout(() => {
  47. yieldOne();
  48. }, 40);
  49. WScript.SetTimeout(() => {
  50. yieldOne();
  51. }, 60);
  52. WScript.SetTimeout(() => {
  53. yieldOne();
  54. }, 1000);
  55. WScript.SetTimeout(() => {
  56. writeTTDLog(ttdLogURI);
  57. }, 1000);