The best way to access the value of a fulfilled Promise while debugging

I've been using this loopback application in my IntelliJ IDE. I set a breakpoint at the promise in calculator.controller.ts, where the code looks like this:

  @get('/multiply/{intA}/{intB}')
  async multiply(
    @param.path.integer('intA') intA: number,
    @param.path.integer('intB') intB: number,
  ): Promise<MultiplyResponse> {

    const response =  this.calculatorService.multiply(<CalculatorParameters>{
      intA,
      intB,
    });
    return response;
  }

When I run the debugger, it stops at two breakpoints. The first one is here:

https://i.stack.imgur.com/TEBVu.png

The second breakpoint occurs here:

https://i.stack.imgur.com/b9I6z.png

At both points, the Promise status is pending. How can I configure the debugger to display the value when the Promise status changes to fulfilled?

Answer №1

It's crucial to grasp the concept of a promise. A promise doesn't actually hold the value itself; instead, it outlines the plan for retrieving it. So, at your second breakpoint, nothing has really occurred yet.

If you're looking to access a value, you must use the await keyword.

const response = await ....

Since you've declared your method as async, it is necessary to include an await; otherwise, it won't serve any purpose.

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

Swap out a collection of objects for a different collection of objects

I need to replace the content of array1 with the content of another array2 while keeping the same references and indexes in array1: let array1 = [ { book : { id : 2, authorId : 3} } , { book : { id : 3, authorId : 3} }, { book : { id : 4, authorId : ...

executing bower via TeamCity on Windows

In my project's build steps using Team City 9.0c, there is a task that involves running the command bower install without any parameters. Although Bower is installed on the system (I can execute it via the command prompt), I encountered the following ...

TypeScript - The key is missing from the type definition, yet it is present in reality

I'm currently working on developing my own XML builder using TypeScript, but I've run into a significant issue: Property 'children' does not exist in type 'XMLNode'. Property 'children' does not exist in type &apos ...

Methods to acquire the 'this' type in TypeScript

class A { method : this = () => this; } My goal is for this to represent the current class when used as a return type, specifically a subclass of A. Therefore, the method should only return values of the same type as the class (not limited to just ...

How can you selectively export a single function from a JavaScript file?

Within my project, I have two separate modules - one written in ts and the other in js. There is a utility within the js module that needs to be accessed by the ts module. The utility service.js looks like this: module.exports = { helloFriends: functi ...

Exploring Angular: Embracing the Power of Query String Parameters

I've been struggling with subscribing to query string parameters in Angular 2+. Despite looking at various examples, I can't seem to make it work. For instance, on this Stack Overflow thread, the question is about obtaining query parameters from ...

Creating unique random shapes within a larger shape on a canvas, as shown in the image

I have a parent rectangle and would like to add up to 10 or fewer rectangles on the right-hand side corner of the parent rectangle, as shown in the image below: I attempted to write code to achieve this, but the alignment is off-center from the parent rec ...

Transmit information from the backend Node.js to the frontend (without using sockets)

Is there a method to transfer data from my socket, for example example.com:8000, to my web server that is not on the same socket at example.com/index.php? I've searched through various codes but have not come across any solutions yet. If you could pro ...

Steps to simulate a TouchEvent programmatically using TypeScript

Is there a way to manually trigger the touch event in TypeScript? In JavaScript, it was possible but I am struggling to achieve the same in TypeScript. For example: let touchStart: TouchEvent = document.createEvent('TouchEvent'); touchStart.i ...

The double command in the package.json file is malfunctioning

I am working on an app where I need to bring together all my handlebars templates and partials. When I run the following commands (using npx since it is a local package): Building Views: npx handlebars ./public/templates/views -f ./public/templates/view ...

Issue: Module 'stylelint' not found in Angular Project

I've been attempting to execute this command to validate all of the .scss files (and even tried with .css files) and I keep encountering this error. $ stylelint "apps/**/*.scss" It worked once before but not anymore, even after restarting my compute ...

How can we go about installing node using npm through brew at this moment?

I successfully installed node on my macOS using Homebrew. brew install node Upon installation, node shows the correct version: $ node -v v8.4.0 However, when I try to check the npm version with: $ npm -v I receive the error message -bash: /usr/loca ...

The Allure Report runs successfully but encounters issues with data population when using Jasmine and Protractor

Currently, I am facing an issue with my Protractor project set up that incorporates Allure Reporting. Although the Allure Reporter successfully outputs the HTML file to the allure-report directory, when I attempt to view it in a browser, all I see is a "Lo ...

Using third-party libraries like jQuery, CSS, and JavaScript in your React project by directly importing them into the index.html file can be a more efficient approach compared

When working with React, is it advisable to import external JavaScript, jQuery, and CSS files into the index.html file in the public folder? Are there any potential performance implications associated with this practice? I have utilized some jQuery functi ...

Tips for ensuring only one property is present in a Typescript interface

Consider the React component interface below: export interface MyInterface { name: string; isEasy?: boolean; isMedium?: boolean; isHard?: boolean; } This component must accept only one property from isEasy, isMedium, or isHard For example: <M ...

Exported data in Vue3 components cannot be accessed inside the component itself

Essentially, I'm working on creating a dynamic array in Vue3. Each time a button is clicked, the length of the array should increase. Below is the code snippet. <div class="package-item" v-for="n in arraySize"></div> e ...

The issue is that the browser is not refreshing after making changes to files while running a browsersync task using

While using an npm scripts task to launch a browsersync server that is supposed to refresh after file updates, I've encountered an issue... The task named serve is defined in the scripts property of the package.json like this: { ... "scripts ...

Leveraging ngIf and ngFor within choice

Is there a way to combine ngIf and ngFor in a single line of code? Here is the code snippet I am currently using: <option *ngIf="tmpLanguage.id!=languages.id" *ngFor="let tmpLanguage of languages" [ngValue]="tmpLanguage.id"> {{tmpLang ...

Uncovering a port alternative to 3000 using Express and Docker

My current project involves running an Express app using Docker and everything functions properly when it is operated on port 3000. The Dockerfile utilized for this purpose is as follows: FROM node:boron # Create app directory RUN mkdir -p /usr/src/app W ...

Set up npm installation proxy

How can I successfully configure Node to download packages using npm install while working within a company with a proxy? I've attempted running commands like : npm config set https-proxy "http://company%5Cuser:password@server:port/" However, the c ...