Closed IAkumaI closed 2 months ago
Any reply?
Hello - Thanks for the implementation and tests! It took me some time to find time to discuss this with Nate.
We do eventually want to move Racer to a Promise-based API, but we want to take it slower. Once it's in the public API, we have to much more careful to not cause breaking changes, without a new major version.
We'd be OK for now with adding Promise versions of fetch
, subscribe
, and whenNothingPending
.
However, for the mutator methods, we want to think some more about what the APIs would look like, since many of them currently have return values. Such as model.set()
returning the previous value set at that path.
The nice thing is, if you want to do this today, you can still do the augmentation of Model.prototype
from your own code.
Thanks for the reply. What is wrong with async mutators with return values? Async functions can return values as well as normal functions. I do not see the problem here.
In current implementation it just call resolve(result);
, so you can do this:
let prevValue = await model.setAsync('path', 'new value');
In fact this PR is just promisify
for callback-methods. Better if you will rewrite orifinal methods, but, yes, this will break current API (it is the reason why I didn't it).
Async methods were added with Racer v2
Hi. I added async versions (it returns Promise) of most methods of Model and Query. And created some tests for it.
If method returns some value it will be passed to resolve() All methods has name {original}Async. So, now you can write code with async/await
What do you think about moveing to promise-based racer?