Within our typescript code base, there is a recurring code pattern:
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);
}
});
}
We are exploring ways to streamline the code and avoid repeating most of the existing structure. Ideally, we would like it to resemble something along the lines of:
public async publish(event: myEvent, myStr: string): Promise<void> {
return new HelperOfSomeSort() {
this.doCoolStuff(event, myStr);
}
}
Do you think this simplification is achievable?