Questions tagged [es6-promise]

An ES6 Promise is an ECMAScript 2015 object that represents an in-progress asynchronous operation

An ES6 Promise is an ECMAScript 2015 (ES6) object that represents the eventual completion or failure of an asynchronous operation. The ES6 Promise API is based on the Promises/A+ specification.

Consumer-side, a promise is essentially a returned object to attach callbacks to, instead of passing callbacks into a function. The .then function lets callers chain operations to be run subsequently.

In an ideal world, all asynchronous functions would return promises. However, a promise may also be created from scratch using its constructor, to wrap old callback-style function calls.

Promise objects have three possible states:

  • Pending
  • Fulfilled
  • Rejected

Resources

Related Tages

5243 questions
1
vote
0 answers

React and Typescript, createContext where the default value is a Promise

I am learning React and Typescript and following this tutorial (AWS Cognito + React JS Tutorial: Getting Sessions and Logging out (2020) [Cognito Episode #3] https://youtu.be/T7tXYHy0wKE). I am trying to call my new React Context with…
1
vote
2 answers

I want to await a function to complete then run another function

This is the code I am trying with: const arr = ['a' , 'b' ,'c', 'd'] const func = async () => { let i = 0 let interval = setInterval(() => { let x = arr[i++ % arr.length] console.log(x) if (i === 4 ) { …
1
vote
1 answer

Frontend promise always pending backend node js call

I have my react frontend which is very basic right now as i just want to retrieve some data from my backend api written in node js which calls and external api the data is fetched properly to the backend as I have tested it by printing the data. The…
program.exe
  • 451
  • 4
  • 12
1
vote
2 answers

async await for function with private variables and methods

I have created a simply function with sub functions that returns balance and you can add an amount to update your balance. const bankAccount = (initialBalance) => { let balance = initialBalance; return { getBalance: function() { …
1
vote
2 answers

Loop setTimeout with Promise

To ensure that execution duration is shorter than interval frequency, I a recursive pattern for the setTimeout function. But if I combine it with Promise the output "The End" is executed before the loop ends. How to use Promise correctly, or is…
Hölderlin
  • 424
  • 1
  • 3
  • 16
1
vote
1 answer

How to send status 200 callback to api gateway from async lambda , without waiting for lambda execution to complete?

I am creating an async lambda function in Node.Js. There some promised functions used sequentially using Promise.all() . I have another non-promise function which will send callback to api gateway with status 200. But this non-promise function is…
Fury
  • 151
  • 1
  • 9
1
vote
1 answer

Difference between Promise.resolve and empty Promise Object

What is the difference between using Promise below ways. Way 1: function xyz() { return Promise.resolve(); } Way 2. function xyz() { return new Promise(() => {}); } So, in a project i was been following they switched the return value of…
1
vote
1 answer

Express: next is not called properly inside a catch after await

I have a very simple route router.get('/', async (req, res, next) => { try { const allEmployees = await employees.find({}); res.json(allEmployees); } catch (error) { next(error); } }); It works ok. But after I refactored it with…
Joji
  • 4,703
  • 7
  • 41
  • 86
1
vote
3 answers

javascript promises inside then

I've recently discovered the promises, and they made my life much easier. But there is a specific case that I'm not being capable to handle. It is when I have to call a promise inside then(). Here is my code: const firebaseAuth =…
Cesar Lopes
  • 373
  • 1
  • 10
1
vote
0 answers

Mongoose second promise doesn't insert document

I am learning Node js and Mongoose. This is my code with Promise all, for some reason, it doesn't insert only second value: { name: "test bulk 3", email: "testb3@test.ru", zipcode: 56353 }, I tested to replace items,…
1
vote
1 answer

Calling .finally on a promise that is try/catch handled elsewhere causes UnhandledPromiseRejection in nodejs

I've recently encountered a weird behavior with nodejs. I'll explain with the following example: let's say we have two functions, foo and bar, foo creates a promise, calls .finally() on it, and returns it. bar on the other hand, wraps the promise…
1
vote
1 answer

CsvError: Invalid Opening Quote: a quote is found inside a field at line 9618

I have this error when I try to parse kepler_data.csv using csv-parse using promises following Adam and Andre Negoi NodeJS course. Here is the code: function loadPlanetsData() { return new Promise((resolve, reject) => { …
Sycan
  • 37
  • 8
1
vote
1 answer

Return a promise with async/await inside then

Im quite familiar with javascript but I'm a bit confuse with Promise, Async/Await How do I add async/await to modify a promise data and return the original Promise e.g. this working fine function test() { const data = { sample: 1, …
SymmetricsWeb
  • 586
  • 6
  • 20
1
vote
2 answers

Why Promise.race([Promise.resolve(1), 2]).then(console.log) returns 1 instead of 2?

Why does this behavior happen with Promise.race(), that Promise.resolve(1) calculates faster rather than just 2? Promise.race([Promise.resolve(1), 2]).then(console.log)
1
vote
1 answer

How to convert Axios data to Fetch body in POST method?

Well this is my Axios POST request: import React, {useState} from "react"; import Axios from "axios"; const [data, setData] = useState({ number: "", password: "", code: "" }) function handle(e) { const newdata = { ...data }; …
SoliMoli
  • 781
  • 2
  • 6
  • 25