I would rather export const asyncWrapper = async (fn, ...args) => {
Secondly, a general practice I have often seen is that error is always the first param, while the rest are the response from the function call.
👋 I enjoy programming in JavaScript. My industry experience is in Angular and Ionic Framework. I teach fundamentals of JavaScript and front-end frameworks in Oslo.
P.S. I love hamburgers. 🍔
I initially used a closure and thought of using the rest operator there, but I didn't like the syntax. Although, it does afford the ability to create functions to use later.
constfetchUsers=asyncWrapper(fetchUsersRequest);// some other codeconst[users,error]=awaitfetchUsers();
I didn't see a need for this right now and decided to simplify it.
👋 I enjoy programming in JavaScript. My industry experience is in Angular and Ionic Framework. I teach fundamentals of JavaScript and front-end frameworks in Oslo.
P.S. I love hamburgers. 🍔
Hey! Thanks for the feedback! I do prefer the flexibility of the rest params, but for this example I didn't have a need for it. 😊 It would be great to refine the function as the use cases start changing.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I would rather
export const asyncWrapper = async (fn, ...args) => {
Secondly, a general practice I have often seen is that
error
is always the first param, while the rest are the response from the function call.return [error, response]
;I initially used a closure and thought of using the rest operator there, but I didn't like the syntax. Although, it does afford the ability to create functions to use later.
I didn't see a need for this right now and decided to simplify it.
Hey! Thanks for the feedback! I do prefer the flexibility of the rest params, but for this example I didn't have a need for it. 😊 It would be great to refine the function as the use cases start changing.