A Javascript promise that perpetually stays in a pending state

Utilizing the rotateByDegrees function from a library called node-poweredup within a typescript project:

motor.rotateByDegrees(20,10).then(function(value) {console.log("test");}, function(value) {console.log("error");});

Expecting to see "test" after successful completion, however, the promise remains unresolved. When using await, it gets stuck on the await line indefinitely. Attempting to replicate the syntax utilized in the rotateByDegrees function:

let promise = new Promise((resolve) => { return resolve(); });

results in a compilation error:

error TS2794: Expected 1 arguments, but got 0. Did you forget to include 'void' in your type argument to 'Promise'?
I can get it to compile and function as anticipated with resolve(true), but how is it compiling in the library then? Is my understanding of promises incorrect? Could this be related to a TypeScript feature or possibly a bug in the library? As a newcomer to JavaScript, I want to avoid over-complicating things by including irrelevant information. If you could provide insight into what I might be overlooking and suggestions for debugging this issue, I would be able to offer any necessary details.

Answer №1

After receiving some helpful feedback, I was able to narrow down the issue to the compilation of the library. Instead of using a pre-compiled binary, I had to compile the library myself using electron-rebuild in order to get the bluetooth adapter to work properly. Here is the test I conducted:

git clone https://github.com/nathankellenicki/node-poweredup.git
cd node-poweredup
npm install
npm run build

The compilation process went smoothly without any errors. I then created a test file with the following content:

const PoweredUP = require("node-poweredup");

const poweredUP = new PoweredUP.PoweredUP();
poweredUP.scan(); // Initiating hub scan

console.log("Looking for Hubs...");

poweredUP.on("discover", async (hub) => { // Waiting for hubs to be discovered

    await hub.connect(); // Establishing connection to hub
    console.log(`Connected to ${hub.name}!`);

    const motorA = await hub.waitForDeviceAtPort("A"); // Ensuring a motor is plugged into port A
    motorA.rotateByDegrees(20,10).then(function(value) {console.log("test");});

});

As expected, when running the test file, I obtained the following output:

node-poweredup$ node test.js 
Looking for Hubs...
Connected to MyHub2!
test
Connected to MyHub3!
test

However, when I modified the first line to use my self-compiled binary as follows:

const PoweredUP = require(".");

The output changed to:

node-poweredup$ node test.js 
Looking for Hubs...
Connected to MyHub2!
Connected to MyHub3!

Although this doesn't provide a complete solution, it does give me a clue about where to start investigating the discrepancy in compilation results on my machine.

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

Using react hooks, I am refreshing the product image by replacing it with the thumbnail image

I'm currently working on an e-commerce platform that resembles Amazon. In the product detail page, I want the right side image to update when I click on a thumbnail image on the left side. The issue I'm facing is that upon first loading, the def ...

Exploring the combination of Babel and Next.js: Integrating custom scripts into a project

Hello, I am currently learning next.js and facing a common issue that I need help with. I have created my own ES6 JavaScript library and now I want to convert it to babel so I can use it in my next.js application. Is there a way to configure babel for sp ...

Unfortunately, the YouTube iframe Embed feature does not have the ability to adjust audio settings on an

I've been experimenting with the YouTube iframe API and created a simple set of player controls for the YouTube player using Flash CC HTML5 canvas. The controls include a play/pause button, a draggable video bar with buffering visualization, and a vol ...

Using JQuery to Iterate Through All Form Inputs

I am attempting to retrieve the values of all input fields from a form using JQuery and store them in an array to be sent via AJAX with a GET request. My initial approach did not yield the desired results: function gatherFormData(){ $('#formId i ...

Fine-tuning CSS layout based on perspective alteration

I am working with the following code: function exportTableToExcel(tableID, filename = ''){ var downloadLink; var dataType = 'application/vnd.ms-excel'; var tableSelect = document.getElementById(tableID); var tableHT ...

sudden swivel when shifting camera while following an object on a flat surface/pathway

I'm relatively new to three.js and I'm eager to create a scenario where a cube or object moves on a flat surface or road. I have managed to move the object in the z direction, but now I want to move the camera as well, giving the impression of a ...

Electron Builder reminder: Make sure to include the author's email in the application package.json file

Encountering an Issue During Generation of Build Using Electron Builder. ⨯ Please provide the author's 'email' in the application package.json I attempted to add the email field to the package.json file as well. ...

How can I retrieve the name of a React component in the most effective way?

My current challenge is figuring out how to retrieve the name of a React component. I initially attempted using the this.constructor.name property, but discovered that it doesn't function properly in production mode due to code minification by Webpack ...

Check if an object is already in an array before pushing it in: JavaScript

Summary: I am facing an issue with adding products to the cart on a webpage. There are 10 different "add to cart" buttons for 10 different products. When a user clicks on the button, the product should be added to the this.itemsInCart array if it is not a ...

Here's a guide on executing both GET and POST requests using a single form

Currently, I am developing a web application which involves using a GET request to display checkboxes in a form. The selected data from the checkboxes needs to be sent back to the server using a POST request. However, I'm facing an issue with performi ...

Incorporate a class into the fixed navigation menu using fullpage.js

I am attempting to modify the behavior of a sticky menu as the user scrolls down using fullpage.js. My goal is to have the #top-wrapper behave normally when the first section/page loads, and then add a class of is-fixed as you scroll down. When scrolling ...

Clicking on a button in the Shield UI Grid Toolbar will apply filters to

Currently, I am working with a grid that utilizes a template for the toolbar. In this grid, there is a column labeled "Status." My goal is to filter the rows so that only those where the Status equals Request to Reschedule, Cancelled, Office Call Required, ...

"Optimizing npm packages for front-end web development in vanilla JavaScript: A guide to bundling for production deployments on

My website is built using vanilla HTML/CSS/JavaScript with ES6 modules and can be deployed to GitHub pages and Netlify. I have set up my site by importing "main.js" in my HTML like this: <script src="js/main.js" type="module" defer&g ...

What causes the difference in behavior between using setInterval() with a named function as an argument versus using an anonymous function?

I can't seem to figure out why using the function name in setInterval is causing issues, while passing an anonymous function works perfectly fine. In the example that's not working (it's logging NaN to the console and before the first call, ...

Creating a Visual Presentation with Background Image Transition in HTML, CSS, and JavaScript

Seeking assistance in setting up a basic background image slideshow on my website. I have been unable to locate a suitable tutorial online, so I'm reaching out here for guidance. HTML: <body> <h3>Welcome!</h1> <p>Lorem i ...

experiencing an excessive amount of rerenders when trying to utilize the

When I call the contacts function from the main return, everything seems fine. However, I encounter an error at this point: const showContacts = React.useCallback( (data: UsersQueryHookResult) => { if (data) { return ( < ...

Utilizing Angular's File Upload feature with Glyphicon icons

Has anyone tried to open a local file using bootstrap glyphicon? I found this example at https://jsfiddle.net/JeJenny/ZG9re/, but it doesn't seem to work. Does anyone have any ideas on how to make this approach work with images like glyphicon? main.h ...

Update to Material-UI 4.8.1 - Is there a different method for defining the `component` property now?

Note: Please note that there was a bug in version 4.8.x which caused this issue. To resolve it, make sure to upgrade to version 4.9.0 or above. In the initial version 4.8.0, the following code would compile and run smoothly: <DialogContent> {/* us ...

Exploring the process of sending props via the render method in Vue.js and observing their behavior

Struggling with passing a prop from a parent component down to a child created using CreateElement/render in vue.js and then watching it. Here is the parent component: Vue.component('my-drawing', MyDrawing) new Vue({ el: '#drawing' ...

AngularJS multiple select dropdown with dynamic quantity selection

I am currently utilizing AngularJS instead of Angular and I am looking to implement a corresponding textbox next to the dynamic select box. Below is my code for dynamically adding select boxes: HTML <div ng-controller='MyController'> ...