Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supporting async remote functions #147

Open
Nosfistis opened this issue Aug 31, 2018 · 0 comments
Open

Supporting async remote functions #147

Nosfistis opened this issue Aug 31, 2018 · 0 comments

Comments

@Nosfistis
Copy link

Nosfistis commented Aug 31, 2018

Is it possible that we add a property to support async functions? I have tested it so far using Node's promisify with no problem.

Since every remote method is promisified, even callback-based ones are supported, therefore there seems to be no backward-compatibility problem, although that would set node requirements to version 8.0+. Loopback already supports it as a fallback, and it is possible that fireloop disables the support with a flag.

The required change is:

reference[remote] = function () { Model[remote].apply(Model, arguments); };

changing to:

const { promisify } = require('util'); // TS types might require different import

reference[remote] = async function () {
  const asyncRemote = promisify(Model[remote]);
  try {
    return await asyncRemote.apply(Model, arguments);
  } catch (err) {
    console.error(err);
  }
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant