1function someFunction(username, password) {
2 return new Promise((resolve, reject) => {
3 // Do something with the params username and password...
4 if ( /* everything turned out fine */ ) {
5 resolve("Stuff worked!");
6 } else {
7 reject(Error("It didn't work!"));
8 }
9 });
10}
11
12someFunction(username, password)
13 .then((result) => {
14 // Do something...
15 })
16 .catch((err) => {
17 // Handle the error...
18 });