Junior — Senior
Promise wrapper for authentication function
livecode
Task condition
The project includes an asynchronous function asyncAuth that takes a callback. In this callback, an error (the first parameter) and data received from the server (the second parameter) can be passed. It is required to implement a wrapper function auth that calls asyncAuth but returns a Promise instead of using a callback.
import asyncAuth from '~';
/**
The function `asyncAuth(callback)` accepts a callback, which can
receive an error (as the first argument) and data
from the server (as the second argument).
asyncAuth(error, data) => {});
*
You need to implement the `auth()` function,
which calls `asyncAuth()`, but returns a Promise.
*
@returns (Promise)
*/
function auth() {
asyncAuth((error, data) => {});
}
/**
The `tryAuth()` function uses `auth()` and, in case of an error,
makes N additional attempts.
If all attempts fail, it should return the last error.
*
@returns (Promise)
*/
function tryAuth(n) {
}
The task involves creating a promise wrapper and adding retry logic upon failure, and in case of complete failure, returning the last error.