/
SumApi.js
50 lines (44 loc) · 938 Bytes
/
SumApi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const SumApi = () => {
const sum = (a, b) => a + b;
/**
* Syncronously adds two numbers
*
* @param {number} a The first number to add
* @param {number} b The second number to add
* @returns {number} The sum of a and b
*
* @throws Will throw an error
*/
const GetSumSync = (a, b) => {
try {
return sum(a, b);
} catch (err) {
throw (err);
}
};
/**
* Asyncronously adds two numbers
*
* @param {number} a The first number to add
* @param {number} b The second number to add
* @returns {number} The sum of a and b
*
* @throws Will throw an error
*/
const GetSumAsync = async (a, b) => {
try {
return new Promise((resolve) => {
setTimeout(() => {
resolve(sum(a, b));
}, 3000);
});
} catch (err) {
throw (err);
}
};
return {
GetSumSync,
GetSumAsync,
};
};
module.exports = SumApi();