Skip to content

Supporting async remote functions #147

@Nosfistis

Description

@Nosfistis

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);
  }
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions