1

Is there a way to make a curry function async?

Suppose I have the event handler function below (in my actual use case it is not an event handler), how could I update it to run async? My end goal is to have a curried function that I can await (it will be returning a promise).

foo = () => (event) => {
   this.setState({something:event.target.value});
}
2
  • "curry function" - you mean "arrow function", right? Commented Oct 31, 2018 at 17:34
  • hi georg, curry is a js way of creating customized functions, see here for some explanation Commented Oct 31, 2018 at 17:39

1 Answer 1

4

Keep in mind the 'await' keyword can only be used inside an async function. So, even if you defined an async function - and you called that function from somewhere else - you won't be able to utilize the 'await' keyword. I believe you're looking for this:

const foo = () => async (event) => {
    await performAnAsyncEvent(event);
    this.setState({something:event.target.value});
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.