swc/ecmascript/jsdoc/tests/fixtures/asyncfunction.js

44 lines
806 B
JavaScript
Raw Normal View History

2020-08-14 12:20:25 +03:00
function resolveAfter2Seconds(x) {
return new Promise(resolve => {
setTimeout(() => {
resolve(x);
}, 2000);
});
}
/**
* Add a number.
* @param {number} x - The number to add.
*/
async function add(x) {
var a = resolveAfter2Seconds(20);
var b = resolveAfter2Seconds(30);
return x + await a + await b;
}
/**
* Subtract a number.
* @param {number} x - The number to subtract.
*/
var subtract = async function subtract(x) {
var a = resolveAfter2Seconds(20);
var b = resolveAfter2Seconds(30);
return await a + await b - x;
}
/**
* Adder class.
*/
class Adder {
/**
* Construct an Adder instance.
*/
constructor() {}
/**
* Add a number.
* @param {number} x - The number to add.
*/
async add(x) {}
}