mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[SourceKit] Add a request tracker that manages cancellaiton
Previously, `SwiftASTManager` and `SlowRequestSimulator` maintained their own list of in-progress cancellation tokens. With code completion cancellation coming up, there would need to be yet another place to track in-progress requests, so let’s centralize it. While at it, also support cancelling requests before they are scheduled, eliminating the need for a `sleep` in a test case. The current implementaiton leaks tiny amounts of memory if a request is cancelled after if finishes. I think this is fine because it is a pretty nieche case and the leaked memory is pretty small (a `std::map` entry pointing to a `std::function` + `bool`). Alternatively, we could require the client to always dispose of the cancellation token manually.
This commit is contained in:
@@ -113,7 +113,8 @@ class CursorInfoTest : public ::testing::Test {
|
||||
NullEditorConsumer Consumer;
|
||||
|
||||
public:
|
||||
LangSupport &getLang() { return Ctx.getSwiftLangSupport(); }
|
||||
SourceKit::Context &getContext() { return Ctx; }
|
||||
LangSupport &getLang() { return getContext().getSwiftLangSupport(); }
|
||||
|
||||
void SetUp() override {
|
||||
llvm::InitializeAllTargets();
|
||||
@@ -496,7 +497,7 @@ TEST_F(CursorInfoTest, CursorInfoCancellation) {
|
||||
CursorInfoSema.signal();
|
||||
});
|
||||
|
||||
getLang().cancelRequest(CancellationToken);
|
||||
getContext().getRequestTracker()->cancel(CancellationToken);
|
||||
|
||||
bool expired = CursorInfoSema.wait(30 * 1000);
|
||||
if (expired)
|
||||
|
||||
Reference in New Issue
Block a user