UI thread was blocked due to withProgress being invoked from an external library function

Currently enhancing an extension that is almost finished, but facing a challenge in adding visual cues for lengthy operations. Initially suspected a missing async/await in the code, but struggling to identify the cause. The progress indicator isn't displaying until after the operation completes, and isolating the method blocking the UI thread (commenting it out resolves the issue) led me to discover that the culprit is from an external package in use.

Below is a condensed snippet of the code I'm working with:

import { composeAndValidate } from "@apollo/federation";

vscode.window.withProgress(
{
    location: vscode.ProgressLocation.Notification,
    title: 'Composing',
    cancellable: false
},
async progress => {
    const sdls = await getSdls()

    //The call to composeAndValidate is blocking UI thread
    const results = composeAndValidate(sdls);

    ...some other code
})

//Somewhere else
async function getSdls(){
    ... async stuff
    return [{name: 'test', typeDefs: 'type Query { me: String }`}];
}

Seems like delving deeper into the @apollo/federation library may be necessary, though no Promises are visibly used in those methods (yet to explore further on the graphql-js side). Any suggestions on investigating ways to unblock the UI thread? While most scenarios operate smoothly, larger designs within my extension result in a ~3s delay without triggering VS Code's termination, just causing temporary confusion.

Answer №1

I managed to successfully implement this solution by incorporating the use of the yield keyword. I made a small adjustment to the code snippet provided above, which ultimately solved my issue:

vscode.window.withProgress(
{
    location: vscode.ProgressLocation.Notification,
     title: 'Composing',
     cancellable: false
},
async progress => {
    const sdls = await getSdls()

    //The call to composeAndValidate is blocking UI thread
    const results = getCompositionResults(sdls).next().value;

    ...some other code
})

function* getCompositionResults(sdls){
    yield composeAndValidate(sdls);
}

//Somewhere else
async function getSdls(){
    ... asynchronous operations
    return [{name: 'test', typeDefs: 'type Query { me: String }`}];
}

Note: When using yield, it usually entails converting synchronous processes to asynchronous ones. It's important to familiarize yourself with this concept before implementation, as it proved beneficial in my scenario.

Utilizing yields can be challenging at times since it requires converting many synchronous tasks to asynchronous and ensuring that no assumptions are made about the synchronicity of the code leading to possible data structure modification conflicts.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

React JSX is failing to return either an Icon or String value depending on the input provided by the user for the password

I'm currently developing a registration page where I want to display a message saying "Your password must be at least 12 characters long" or show a green checkmark when the user types a password that meets this requirement. However, nothing is being d ...

Automatically Refresh a Div Element Every 5 Seconds Using jQuery's setInterval() Function

My goal is to refresh the left div every 5 seconds using $.ajax to get JSON data and display 4 random elements in that div. However, even though the left div block refreshes, the content remains the same with the same images always showing. view image desc ...

No files found in dist/ directory when using Vue.js

Beginner's Note I must confess that I am a novice when it comes to web development. Please bear with me if this question seems silly; I appreciate your assistance in advance. Initial Setup My current node version is 16.15.1 and npm version is 9.5.0 ...

What is the best way to extract the geometry information from a gltf object?

I've been using three.js to load a gltf file with the gltfloader, and now I'm trying to create a particle system. However, I'm having trouble getting the geometry object that I need. function initModel() { var planeGeometry = new THREE ...

ERROR_UNSUPPORTED_ESM_URL_SCHEME - issue with next-sitemap plugin

I have a project utilizing next-sitemap with Node.js version v14.11.0. next-sitemap.config.js module.exports = { siteUrl: 'https://*****.com', generateRobotsTxt: true, robotsTxtOptions: { additionalSitemaps: [ 'htt ...

Execute HTML and JS files through Eclipse PDT to view in a web browser

Is it possible to open HTML and JS files in a web browser within Eclipse PDT? Right now, only PHP files seem to launch successfully, otherwise an "Unable to Launch" dialog pops up. Any advice is appreciated! ...

There are a total of 152 issues found in the index.tsx file within the react

Despite everything working correctly, I am continuously encountering these errors. Is this a common occurrence? What steps can I take to resolve them? I have developed my react application using Javascript instead of Typescript; however, I don't belie ...

JavaScript (geolocation) error: Unhandled TypeError - Invocation not allowed

Encountering the Javascript error "Uncaught TypeError: Illegal invocation" while executing the code var nativeGeoloation = window.navigator.geolocation.getCurrentPosition; nativeGeoloation(function (){ alert("ok")}); Despite attempting to call the code w ...

The jQuery script is malfunctioning

I have implemented an order form where users must complete a captcha code verification for cash on delivery. I am using jQuery to validate the entered captcha code. If the entered captcha code is incorrect, I prevent the user from submitting the form and ...

Unable to locate a React component module that has been published

After successfully publishing a React component to NPM, I encountered an issue when trying to use it in another project - I couldn't find the module! Module not found: Can't resolve 'react-subreddit-posts' in '/Users/kyle.calica/C ...

Steps for setting up Node.js or npm on XAMPP

Hello there, I'm new to all of this so please bear with me if I make any mistakes. As a beginner developer, I am currently working on developing a web application locally using XAMPP. My plan is to eventually deploy it using a hosted web service. XAM ...

I am unable to view the GridView features that have been set using jQuery in the JavaScript code on the webpage

I'm facing an issue with the properties of a GridView. On the aspx page, I have a container using a <div>. <div id="DivRecords"> Within this container, I am dynamically adding a GridView using jQuery. In the js file, I am creating the Gr ...

Text located in the bottom right corner of the window with the use of JavaScript

Is there a way to replace text at the bottom right of the window, as opposed to the page, so that it remains fixed in the corner of the window? I'm looking to create a "share" link that is always visible. ...

Performing addition and subtraction calculations with HTML and Javascript

I need help creating a simple HTML table for adding and subtracting values, with a limit of 10 and a minimum of 0. I have two functions set up, additionalAdd and additionalSub, triggered by the onclick event, but I keep getting an error saying that totalAd ...

One way to add a JSON object to an empty JSON array using Javascript involves pushing

Currently, I am facing an issue with an empty JSON array. shoppingCart: [] In addition to the empty array, I also have a JSON object defined as follows: let product = {"name": "name", "price": "price", "quantity": "quantity", "logoPath": "logoPath"}; M ...

The suspense fallback function seems to be missing in NextJS 13

I'm in the process of creating an application to demonstrate the functionality of Suspense in Nextjs 13. However, I'm encountering an issue where the Suspense fallback is not appearing during loading. Below is the code for page.js import React, ...

Dealing with numerous identical ajax requests in jQuery

With 5 text fields where various amounts are entered, I utilize AJAX calls for calculations based on these values. The issue arises when the same AJAX call is repeated each time a user types in order to determine the total amount. The problem lies in the ...

Encountering a surprising token error while running a node.js application with a classic example

I downloaded node.js from its official website and followed the instructions provided here. I attempted to run the example code snippet from the "JavaScript - The Good Parts" textbook: var myObject = { value: 0; increment: function (inc) { this.value ...

What is the best way to use Shadcn to incorporate a calendar that takes up half of my website?

Currently, I am in the process of developing a scheduling appointment system. My main challenge is getting the calendar to take up half of my page's space. Despite my attempts to adjust its height and width, I have not been successful in seeing any ch ...

Ways to prevent an empty iframe from triggering a load event upon injection

I have implemented a technique where I am using an empty frame to handle pseudo-asynchronous form submission. This involves referencing the frame's name attribute in the form's target attribute, allowing the form's action URI to resolve in t ...