Guest User

Untitled

a guest
Oct 19th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. const Time = require('Time');
  2. const Diagnostics = require('Diagnostics');
  3.  
  4. let promise = new Promise((resolve, reject) => {
  5. Time.setTimeout(function() { resolve(1); } , 5000);
  6. // Time.setTimeout(function() { reject("Failed"); }, 5000);
  7. });
  8. promise.then(function(value) {
  9. Diagnostics.log("Then: " + value);
  10. }).catch(function(reason) {
  11. Diagnostics.log("Catch: " + reason);
  12. });
  13.  
  14. class Rectangle {
  15. constructor(height, width) {
  16. this.height = height;
  17. this.width = width;
  18. }
  19. // Getter
  20. get area() {
  21. return this.calcArea();
  22. }
  23. // Method
  24. calcArea() {
  25. return this.height * this.width;
  26. }
  27. }
  28.  
  29. let r = new Rectangle(10, 20);
  30. Diagnostics.log(r.area);
  31.  
  32.  
  33. function resolveAfter2Seconds() {
  34. return new Promise(resolve => {
  35. Time.setTimeout(() => {
  36. resolve('resolved');
  37. }, 2000);
  38. });
  39. }
  40.  
  41. async function asyncCall() {
  42. Diagnostics.log('calling');
  43. var result = await resolveAfter2Seconds();
  44. Diagnostics.log(result);
  45. // expected output: 'resolved'
  46. }
  47.  
  48. asyncCall();
Add Comment
Please, Sign In to add comment