(...args: any[])
| 28 | class AsyncFactory extends Promise<ReturnType<TFactory>> { |
| 29 | protected factory: TFactory; |
| 30 | constructor(...args: any[]) { |
| 31 | if (args.length === 1 && typeof args[0] === 'function') { |
| 32 | // this is being called because a new Promise is being created for an async function invocation (not user code) |
| 33 | super(args[0]); |
| 34 | this.factory = factory; |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | // this is being called because a user is creating an instance of the class, and we want to call the init() method |
| 39 | super((resolve: Resolve<ReturnType<TFactory>>, reject: Reject) => { |
| 40 | try { |
| 41 | // call the factory with the arguments that they provided, then initialize it |
| 42 | initialize(factory(...(args as any)) as any, args).then(resolve).catch(reject); |
| 43 | } catch (error) { |
| 44 | // if the constructor throws, we should reject the promise with that error. |
| 45 | reject(error); |
| 46 | } |
| 47 | }); |
| 48 | this.factory = factory; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | return AsyncFactory as any as new (...args: Parameters<TFactory>) => Promise<Awaited<ReturnType<TFactory>>>; |
nothing calls this directly
no test coverage detected