internal Task <bool> Start(LinkedListNode <Request> node, CancellationToken token, int timeout) { this.token = token; // register a cancellation callback if the token is cancellable, i.e., is not CancellationToken.None if (token.CanBeCanceled) { // Note that if the token is already cancelled, the callback is called synchronously! cancelRegist = token.Register(() => sem.CancellationCallback(node)); } // Create a timer if timeout is not infinite // and the task can be already completed due to a premature cancellation if (timeout != Timeout.Infinite && !Task.IsCompleted) { timer = new Timer((o) => sem.TimeoutCallback(node), null, timeout, Timeout.Infinite); } // return the promise associated task return(Task); }