ServiceStack:异步/等待服务处理程序 [英] ServiceStack: async/await service handlers

查看:52
本文介绍了ServiceStack:异步/等待服务处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have read a few SO questions that touches in this question, even though many of them are several years old:

如何在 ServiceStack API 中编写服务处理程序,使其变为异步/等待?

docs.servicestack.net 上根本没有提到 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?

神话?=)

推荐答案

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

Yes just returning a Task will make your Services Async and non-blocking in ServiceStack.

这篇关于ServiceStack:异步/等待服务处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆