Skip to content

Instantly share code, notes, and snippets.

@nicu-chiciuc
Last active October 20, 2019 12:47
Show Gist options
  • Save nicu-chiciuc/b1f8774dc4246491ac6911e68288872a to your computer and use it in GitHub Desktop.
Save nicu-chiciuc/b1f8774dc4246491ac6911e68288872a to your computer and use it in GitHub Desktop.
import { Meteor } from "meteor/meteor";
import { KnownMethods } from "../methodTypes";
import { FirstArgument } from "meteor/mdg:validated-method";
const callAsync = <TName extends keyof KnownMethods = keyof KnownMethods>(
methodName: TName,
arg: FirstArgument<KnownMethods[TName]>
) =>
new Promise<ReturnType<KnownMethods[TName]>>((resolve, reject) =>
Meteor.call(methodName, arg, (error: Error, result: any) => {
if (error) {
reject(error);
} else {
resolve(result);
}
})
);
export default callAsync;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment