ServiceStack:async/await 个服务处理器

ServiceStack: async/await service handlers

我已经阅读了一些触及这个问题的 SO 问题,尽管其中许多已经有好几年了:

如何在ServiceStack中写一个Service handler API使其变成async/await?

docs.servicestack.net 上根本没有提到 async/await 的文档,我只是找到一些社区论坛帖子。我认为你唯一需要做的就是改变这个非异步方法:

public GetBookingResponse Get(GetBooking getBooking)
{
    Booking booking = _objectGetter.GetBooking(getBooking.Id);
    return new GetBookingResponse(booking);
}

异步方法是这样的:

public async Task<GetBookingResponse> Get(GetBooking getBooking)
{
    Booking booking = await _objectGetter.GetBookingAsync(getBooking.Id);
    return new GetBookingResponse(booking);
}

通过这样做,async/await 模型将神奇地通过调用堆栈加以利用?

神话? =)

是的,只返回一个任务将使您的服务在 ServiceStack 中变得异步和 non-blocking。