[英]What is the best way to implement sequencial http requests with optimistic concurrency in angular?
In this Angular app, the user fills inputs on a table, after each change, the app makes an http request to save changes, with each request, it sends a number which indicates the concurrency version.在这个 Angular 应用程序中,用户在表格中填写输入,每次更改后,应用程序都会发出 http 请求以保存更改,对于每个请求,它都会发送一个表示并发版本的数字。 If the process is successful the server sends a response with the new version.
如果该过程成功,服务器将发送带有新版本的响应。
The problem comes when the user makes changes too fast, the post request will be sent before the previous response is received and therefore the concurrency number will not match.问题来了当用户更改太快时,post 请求将在收到之前的响应之前发送,因此并发数将不匹配。
I am new to angular, so, what is the best way to make a service that can send the requests one after another (one at a time) in a way that this allows me to save the concurrency version from a response to be used in the next request?我是 angular 的新手,所以,制作可以一个接一个(一次一个)发送请求的服务的最佳方式是什么,这样我就可以从响应中保存并发版本以用于下一个要求?
Thanks!谢谢!
It's best to do it using rxjs, it gives you the best way to handle it.最好使用 rxjs 来完成,它为您提供了处理它的最佳方式。
You can follow this , and you can use the appropriate operators based on your needs and requirements.你可以按照这个,你可以根据你的需要和要求使用合适的运算符。
By reading this blog , you'll gain a greater understanding of rxjs.通过阅读这篇博客,您将对 rxjs 有更深入的了解。
For creating sequential http request there is many way to handle it.要创建连续的 http 请求,有很多方法可以处理它。
hope you will get you solution here希望你能在这里得到解决方案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.