-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why does Serializer returns a value, yet Deserializer returns a promise? #138
Comments
Hey @moltar - Because Serializer is a synchronous process and Deserializer can be asynchronous |
I can see cases where Serializer can also be async tho. E.g. when you need to pull up extra data from async sources for example. My point is that the interfaces should be similar. This really took me by surprise. The docs are not even mentioning this for Deserializer. |
I think serializer is never async. It's your job to retrieve the data (async or not) before passing the payload to the serializer. Here's a quick note about promise on the README: https://github.com/SeyZ/jsonapi-serializer#notes-on-promises I understand your point, but not sure it will be valuable to switch to async in the serializer if this is always sync just to be consistent. |
@SeyZ Can you please explain why deserialize needs to be async? There is no code inside deserialize that requires async behaviour!? You are just assuming it should always be non-blocking & forcing that on the user. Surely if the user wanted async they could just wrap the call in a promise of their own? Since you don't have a sync deserialize option I need to look to another library to avoid the overhead of making all my middleware async just for 1 library. |
I'm just stumbling on this also. I'd like to understand how deserializing is ever async? There's no I/O happening as part of this process so I don't really understand how there's any benefit to making this a Promise. Javascript is single threaded (for now at least) and if there's no I/O, there's no appreciable benefit to make this async from what I can tell. Unless I'm missing something about automatically fetching documents through an API or something?? If you have the full payload of an object and you're converting its format, unless you had multiple threads parsing/combining and were coordinating things, I don't see any asynchronous behaviour here. Am I missing something? |
This should not be async. |
I created a PR to adress this. Meanwhile, feel free to use the deployed fork: https://www.npmjs.com/package/jsonapi-serializer-tobilen PS.: This fork will be deprecated from npm if/when the PR is merged |
It feels inconsistent. Any technical reason for that? I think ideally the entire interface should be promise based (and optionally callback based).
The text was updated successfully, but these errors were encountered: