0

I have the following function:

const getMatchedUsers = async () => {
    const term = "test";

    const result = await MatrixClientPeg.get().searchUserDirectory({ term });
    return result.results;
};

When I console.log(getMatchedUsers()), I expect to see an array of users, but I get returned a promise. This surprised me because I assume that when I await the MatrixClientPeg.get().searchUserDirectory({ term }) and store it in the result variable, I'd be able to return it.

Sadly this wasn't the case and I'm not quite sure what's happening. Maybe there's something else in my code that is interfering?

Bobimaru
  • 4,396
  • 5
  • 24
  • 52
  • 1
    All `async` functions return promises. They can't magically make something asynchronous synchronous. They can only make it easier to write code that handles asynchronous processes. – T.J. Crowder Nov 25 '21 at 12:07

0 Answers0