Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Time = require('Time');
- const Diagnostics = require('Diagnostics');
- let promise = new Promise((resolve, reject) => {
- Time.setTimeout(function() { resolve(1); } , 5000);
- // Time.setTimeout(function() { reject("Failed"); }, 5000);
- });
- promise.then(function(value) {
- Diagnostics.log("Then: " + value);
- }).catch(function(reason) {
- Diagnostics.log("Catch: " + reason);
- });
- class Rectangle {
- constructor(height, width) {
- this.height = height;
- this.width = width;
- }
- // Getter
- get area() {
- return this.calcArea();
- }
- // Method
- calcArea() {
- return this.height * this.width;
- }
- }
- let r = new Rectangle(10, 20);
- Diagnostics.log(r.area);
- function resolveAfter2Seconds() {
- return new Promise(resolve => {
- Time.setTimeout(() => {
- resolve('resolved');
- }, 2000);
- });
- }
- async function asyncCall() {
- Diagnostics.log('calling');
- var result = await resolveAfter2Seconds();
- Diagnostics.log(result);
- // expected output: 'resolved'
- }
- asyncCall();
Add Comment
Please, Sign In to add comment