简体   繁体   中英

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:

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? =)

是的,只要返回一个 Task 就会使您的服务在 ServiceStack 中异步和非阻塞。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM