diia-open-source / be-pkg-db

European Union Public License 1.2
4 stars 4 forks source link

Async init of DatabaseService #6

Open tshemsedinov opened 7 months ago

tshemsedinov commented 7 months ago

https://github.com/diia-open-source/be-pkg-db/blob/0ac6f89eb7d1a961ced739c033862527caece65f/src/services/database.ts#L33-L46

Array tasks will be array of empty (undefined) promises, it makes logic of .map unclear, it is recommended to return something from map callback. The fact that Promise resolved/rejected with undefined value will return Promise is not obvious.

Also it is better to use Promise.allSettled instead of Promise.all this will detect all init errors by one start of the server app.

Romick2005 commented 7 months ago

If await this.createDbConnection(dbType, config) will throw new DatabaseError('Failed to connect to Database') then I think the code will end up with unhandled promise rejection. Doesn't it?

tshemsedinov commented 7 months ago

@Romick2005 this error will be added to tasks but it is so unclear... that's why I'd propose to rewrite it in obvious way