If you've ever written an async factory in JS, I bet money somebody came along later and removed it completely. This is an awful pattern and comes from a complete misunderstanding of what a constructor itself is. Also, if you need to initialize an object and set something async up at the same time, just use a helper function lol.
Pretty illuminating, thanks!
First, I was baffled for when I would need this.
But then I saw the async factory function and remembered that I wrote this multiple times, I just didn't call it an async constructor, haha.
I also like the first idea with returning a promise. I think Ember.js did this in many places.
If you've ever written an async factory in JS, I bet money somebody came along later and removed it completely. This is an awful pattern and comes from a complete misunderstanding of what a constructor itself is. Also, if you need to initialize an object and set something async up at the same time, just use a helper function lol.
The static factory helper is the helper function. It just happens to be namespaced within the class for better collocation.