Skip to content

Proper way to handle OperationCancelled #1112

Answered by msujew
sylverek asked this question in Q&A
Discussion options

You must be logged in to vote

Oh, ok that's a neat issue. So basically, what the runCancellable method expects is a function that returns maybe a promise that can be potentially caught. However, if you pass in (doc) => { this.indexManager.updateContent(doc, cancelToken); } the return value is simply void, as the function is not async. The updateContent will create it's own async-await chain that cannot be caught by the language server lifecycle. The following two will work:

// Don't create a new block, this will automatically return the result of `updateContent` from the lambda
await this.runCancelable(documents, DocumentState.IndexedContent, cancelToken, (doc) => 
      this.indexManager.updateContent(doc, cancelToken);

Replies: 2 comments 8 replies

Comment options

You must be logged in to vote
7 replies
@sylverek
Comment options

@msujew
Comment options

@sylverek
Comment options

@msujew
Comment options

Answer selected by sylverek
@sylverek
Comment options

Comment options

You must be logged in to vote
1 reply
@sylverek
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants