-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Description
It is possible to pass cancellation token to .NET invocation and the request to nodeJS can be cancelled.
However, in the same time nodeJS will still execute JS code for the .NET request which have been already cancelled.
So it will be nice to have cancellation token as argument in JS module execution function so JS code can be also cancelled.
The solution example is below.
It is possible to create simple JS object like below to handle cancellation tokens in nodeJS:
type CancellationToken
{
isCancellationRequested: boolean;
signal: AbortSignal; // can be used to cancel requests from module execution function
}Initialize the object on request:
const abortController = new AbortController();
const cancellationToken : CancellationToken = { isCancellationRequested: false, signal: abortController.signal };Subscribe on request cancellation:
req.connection.on('close', function (){
cancellationToken.isCancellationRequested = true;
abortController.abort();
});Then this cancellation token can be checked inside module execution function to skip/stop async js code execution.
fetch(url, { signal: cancellationToken.signal }).then(...);
...
if (cancellationToken.isCancellationRequested)
return;Feel free to change the provided above solution. This is just example what I expect to have )
Metadata
Metadata
Assignees
Labels
No labels