ServiceStack: async/await service handlers

纵然是瞬间 提交于 2021-02-10 07:25:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!