We have a common code pattern in our typescript code base:
public async publish(event: myEvent, myStr: string): Promise<void> {
return new Promise<void>(async (resolve, reject) => {
try {
await this.doCoolStuff(event, myStr);
return resolve();
} catch (error) {
return reject(error);
}
});
}
Looking to simplify the code to not repeat most of that body, so that it looks something in the ballpark of:
public async publish(event: myEvent, myStr: string): Promise<void> {
return new HelperOfSomeSort() {
this.doCoolStuff(event, myStr);
}
}
Is this possible?