promise_MultipleThenCalls.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. let val = -7
  6. let turi = '';
  7. let elog = () => {};
  8. let tlog = (msg, val) => { console.log(msg); }
  9. if (typeof telemetryLog !== 'undefined') {
  10. tlog = telemetryLog;
  11. elog = emitTTDLog;
  12. turi = ttdLogURI;
  13. }
  14. function addThens()
  15. {
  16. let resolveFunc;
  17. const p = new Promise((resolve, reject) => {
  18. resolveFunc = resolve;
  19. });
  20. WScript.SetTimeout(() => {
  21. p.then(() => {
  22. val = val * 3;
  23. });
  24. }, 200);
  25. WScript.SetTimeout(() => {
  26. p.then(() => {
  27. val = val + 21
  28. });
  29. }, 300);
  30. WScript.SetTimeout(resolveFunc, 400);
  31. WScript.SetTimeout(testFunction, 1000);
  32. }
  33. WScript.SetTimeout(addThens, 100);
  34. function testFunction()
  35. {
  36. tlog(`val is ${val} (Expect 0)`, true);
  37. elog(turi);
  38. }