• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ES2PANDA_LSP_CANCELLATION_TOKEN_H
17 #define ES2PANDA_LSP_CANCELLATION_TOKEN_H
18 
19 #include <ctime>
20 namespace ark::es2panda::lsp {
21 // This class needs to be implemented by the server, we need a way to know
22 // if the $/cancelRequest notification has been sent over by the client.
23 // the CancellationToken Class only there to give API's to ability to
24 // check if they should stop or not.
25 class HostCancellationToken {
26 public:
27     virtual bool IsCancellationRequested() = 0;
28 };
29 
30 class CancellationToken {
31 public:
32     bool IsCancellationRequested();
33     bool ThrottledCancellationCheck();
34     CancellationToken(time_t designatedThrottleTime, HostCancellationToken *hostCancellationToken);
CancellationToken()35     CancellationToken() : lastCancellationTime_(0), throttleTime_(0), host_(nullptr) {}
36 
37 private:
38     time_t lastCancellationTime_;
39     time_t throttleTime_;
40     HostCancellationToken *host_;
41 };
42 }  // namespace ark::es2panda::lsp
43 
44 #endif
45