-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Conversation
…FromSync Route static builder methods
Looks good to me! Let's get a second pair of eyes on in and then pull it @NancyFx/most-valued-minions |
@@ -81,6 +81,7 @@ public Task<dynamic> Invoke(DynamicDictionary parameters, CancellationToken canc | |||
/// <param name="description"></param> | |||
/// <param name="syncFunc">The action that should take place when the route is invoked.</param> | |||
/// <returns>A Route instance</returns> | |||
[Obsolete("Sync routes are deprecated (see LegacyNancyModule")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Missing )
at the end.
LGTM (modulo one tiny nit) |
Fixed the typo - also had a think about View etc. and I think we can potentially move all the current things that return Response to be async then add some code to either the conneg, or just before the connect, that does:
e.g. If View["foo"] was executed from a legacy module it would return Task as the dynamic response, which would automatically get "unwrapped" into ViewResult before going into conneg. |
can it be non async? |
Yep, previously it would have been horrible because you'd have to return Task, but async handles all that for you so as long as you mark the delegate as async you can do:
|
So I can still return "Foo" without the async keyword so it becomes On 25 January 2016 at 11:42, Steven Robbins [email protected]
|
I'm not sure I'd add |
What I'm getting at is I shouldn't mark On 25 January 2016 at 11:43, Kristian Hellang [email protected]
|
Each to their own, Task.FromResult will work fine, but the generated state machines are heavily optimised for this use case with async/await (which they weren't with Tasks, hence Nancy's original Task helper stuff) |
@jchannon Right. So |
@jchannon : it does serve a purpose, it changes the return type to Task and unwraps it for you, otherwise you have to return a Task yourself, you can't just return a string. |
@grumpydev That could potentially block, right? |
Block or deadlock? It could block yes, but that's what the legacy stuff would do anyway, this is just another step towards everything being async under the hood (the response class should be next, but view engine generation etc) |
Oh, this is if a route in a legacy module is returning a |
Yeah, the configure await is there to hopefully avoid deadlocks, this idea was just to enable us to move things like Response and View to returning Task rather than just T without breaking the legacy stuff . |
But isn't making something async when it isn't async causing unnecessary On 25 January 2016 at 11:52, Steven Robbins [email protected]
|
👍 |
@jchannon : no, that's where the optimisation comes in (previously hand rolled, now using async/await), if a Task is already complete (which it will be when using Task.FromResult or using an async method with no awaits) then it just executes the next code directly. |
OK cool On 25 January 2016 at 12:12, Steven Robbins [email protected]
|
I think @khellang mentioned |
TL;DR - Find/replace
NancyModule
withLegacyNancyModule
for backwards compatibility.The "old"
NancyModule
is nowLegacyNancyModule
and marked with anObsoleteAttribute
, this can be continued to be used for the immediate future, but the newNancyModule
, which has async "only" routing, is the new standard moving forwards. The newNancyModule
route definitions are the same as the oldNancyModule
"async" definitions, but without the pointless boolean on the end, e.g. this:Becomes:
The initial plan was to use some kind of inheritance to handle the
LegacyNancyModule
, but this isn't possible as it would hit the same issue of only differing on return type as the original asyncNancyModule
work.All the demos have been updated to use
LegacyNancyModule
rather than reworked to use the new one - this should serve as a reminder that we do need to remove it at some point :)In addition to this work we could also do with
Task<dynamic>
versions ofView
,Negotiate
etc., although some of those might be tricky as we may hit the "can't differ by return type" issue again so we need to have a think about that.