问题
I have read a few SO questions that touches in this question, even though many of them are several years old:
How do you write a Service handler in ServiceStack API so that it becomes async/await?
There are no docs on docs.servicestack.net that mentions async/await at all, I just find some community forum posts. 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? =)
回答1:
Yes just returning a Task will make your Services Async and non-blocking in ServiceStack.
来源:https://stackoverflow.com/questions/56672363/servicestack-async-await-service-handlers