Ted
Ted

Reputation: 20184

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

Upvotes: 2

Views: 526

Answers (1)

mythz
mythz

Reputation: 143284

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

Upvotes: 2

Related Questions