[英]ServiceStack: async/await service handlers
I have read a few SO questions that touches in this question, even though many of them are several years old:我已经阅读了一些涉及这个问题的 SO 问题,尽管其中许多问题已经有好几年了:
How do you write a Service handler in ServiceStack API so that it becomes async/await?您如何在 ServiceStack API 中编写服务处理程序,使其变为 async/await?
There are no docs on docs.servicestack.net that mentions async/await at all, I just find some community forum posts. docs.servicestack.net 上根本没有提到 async/await 的文档,我只是找到了一些社区论坛帖子。 I think that the only thing you need to do, to change this non-async method:
我认为你唯一需要做的就是改变这个非异步方法:
public GetBookingResponse Get(GetBooking getBooking)
{
Booking booking = _objectGetter.GetBooking(getBooking.Id);
return new GetBookingResponse(booking);
}
to an async method, is this:到异步方法,是这样的:
public async Task<GetBookingResponse> Get(GetBooking getBooking)
{
Booking booking = await _objectGetter.GetBookingAsync(getBooking.Id);
return new GetBookingResponse(booking);
}
and by doing this, the async/await model will magically be leveraged through the call stack?通过这样做,异步/等待模型将通过调用堆栈神奇地被利用?
Mythz?神话? =)
=)
是的,只要返回一个 Task 就会使您的服务在 ServiceStack 中异步和非阻塞。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.