JamesRandall / FunctionMonkey

Write more elegant Azure Functions with less boilerplate, more consistency, and support for REST APIs. Docs can be found at https://functionmonkey.azurefromthetrenches.com
MIT License
294 stars 50 forks source link

Add support of CancellationToken #107

Closed alexeymarkov closed 4 years ago

alexeymarkov commented 4 years ago

Hi James,

It is automatically injected into a function. Please pass it to DispatchAsync. For token validation and for other "awaitable" methods I would also make sense to pass a CancellationToken. Thanx!

Regards, Alexey

JamesRandall commented 4 years ago

Posting guidance over from #106

Regarding CancellationToken pay attention there are two of them : one injected into a function and another one from HttpContext.RequestAborted. If you cancel a http request only the second is triggered which makes the first useless IMHO. Maybe combining them into a single could be a solution (for http and for signalr triggers). Have a look at CancellationTokenSource.CreateLinkedTokenSource.

JamesRandall commented 4 years ago

Resolved, a combined source has been used for http based triggers. Will push out in beta2 today.

cocowalla commented 4 years ago

Not sure if I'm missing something, but ICommandHandler<TCommand, TResult>.ExecuteAsync doesn't have a CancellationToken argument? Is there some other way to get a ct my handlers can use?

(I'm on 4.0.56-beta.4)

alexeymarkov commented 4 years ago

Use ICancellableCommandHandler instead of ICommandHandler It has Task ExecuteAsync(TCommand command, TResult previousResult, CancellationToken cancellationToken)

cocowalla commented 4 years ago

@alexeymarkov ah, excellent, thanks!