Questions tagged [es6-promise]

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

0
votes
2answers
7 views

promise async data extract issue

loadcsv(file: File): string[] { let csvRecordsArray: string[]; this.parse(file).then((p) => {console.log(p); csvRecordsArray = p as string[]; } ); console.log('mydata', ...
0
votes
1answer
42 views

Strange behaviour in javascript Promise

Considering code snippet below, function one(){ var prm = new Promise(function(resolve,reject){ }); prm.customKey = function(){ } return prm; } function two(){ return one()....
0
votes
0answers
20 views

Why a rejected parameter of a promise works outside of its scope?

See, a promise have two parameters resolved and rejected. So by calling then, you are passing it 2 parameters. router.route('/issue/add').post((req,res) => { let issue= new Issue(req.body); ...
1
vote
1answer
15 views

How to use iterators and Async await to query a google cloud spanner table T1 while querying a second table T2 for each record in T1

I have two tables in Google cloud spanner database - Authors and Books. const request = { schema: [ CREATE TABLE Authors ( AuthorId INT64 NOT NULL, FirstName STRING(1024), ...
0
votes
0answers
35 views

How to iterate over a Response Object

I'm making a fetch call to an API using a little fetch wrapper that returns a Promise.reject if there's an error. function fetchErrorHandler(url, options) { if (options == null) options = {}; ...
0
votes
2answers
38 views

Using setTimeout with no timeout value while evaluating result of Promise.all

The Promise.all MDN docs contain an example of evaluating multiple Promise.all results, but within a setTimeout function without a timeout value. From the docs: // this will be counted as if the ...
0
votes
0answers
22 views

Javascript: generalizing react-loadable with closure

I am using react-loadable to load the views. The code below works fine: const Home = Loadable({ loader: () => import ('./views/home'), loading: Loading, }); But I have multiple ...
-2
votes
1answer
31 views

Why promise.then() behaves asynchronously? [duplicate]

In the below code why promise.then() behaves asynchronously. In other words , why browser is not waiting for the code written inside promise.then() method to be executed?.What tell the browser engine ...
0
votes
0answers
29 views

Uncaught (in promise) TypeError : Cannot read property 'slice' of undefined

I was doing an exercise and not that expert at JS, and used I Axiosas part of the topic and tried to do MVC pattern on JS. I'm stuck with this error for hours now. I tried to surround it with try/...
0
votes
1answer
29 views

Waiting for all elements to fully with Promise.all

I've been trying to figure out how Promises work with a rather simple example: one that fetches a number of images, loads it onto the page in order, counts the number of images loaded. const addImg = ...
0
votes
1answer
18 views

How to turn Firestore query into a Javascript array

I am trying to export a firestore function that performs a query and returns an array containing the objects in that query. I am trying to get data from a subcollection of a document, and get an ...
0
votes
1answer
45 views

Promise.all then callback executed only one time

I have this code part, loading 3 AJAX requests and generate charts: class IncidentStats { constructor($statsForm) { this.$statsForm = $statsForm; this.charts = []; this.$statsForm.on('...
1
vote
4answers
47 views

The first then for my promise returns a promise even though the rejected method has no return function in it

In the code below, the first .then() chained to the addTwo function calls the reject method because I'm checking if type of a and b are "choco", which is impossible. I expected the output to stop at ...
-1
votes
1answer
17 views

Getting an error using Promise.all in react

I've been using axios.get for my api requests, but I was testing out how to pull multiple api requests in on componentDidMount. I have been looking this up and using other peoples code, and decided ...
0
votes
0answers
23 views

Can I return from an `async` function from within a nested callback? [duplicate]

I've got a pretty strong grasp of ES6, but I can't wrap my head around this: How can I return from an async function from within a nested callback? e.g.: async function test () { ...
0
votes
0answers
25 views

scoping + d3.js v5 json reading

I have a very simple question that someone who's much more experienced at JS will be able to answer in a couple of seconds. I'm wondering why when I declare a variable (dataset1) with the let-keyword,...
0
votes
1answer
24 views

JavaScript Promise with FileReader

I'm trying to return a split array when a user specifies a text file in an input box using promises, but the console.log keeps returning undefined, despite resolve actually finding the data. I know ...
0
votes
2answers
59 views

Promise.then not being invoked

In continuation to my question, I have created JavaScript class that takes a remote url as parameter and then uploads the file to S3 (via axios). Here is the class: const config = require('../config....
0
votes
1answer
46 views

Having issue with state variable in react js. Cannot update the variable's value to true

import getAuthentication from './getAuthentication'; class Home extends React. Component { constructor() { super(); //this.authentication = false; this.state = { ...
0
votes
1answer
36 views

Get data from a Promise

I'm working with Tabletop.js to get data from my Google Spreadsheet. In the function, I've invoked a Promise. The only problem is I can't get the data(which is an Array) out of the function. I have ...
1
vote
2answers
32 views

Chain promises in class without using .then

This is part of a larger problem, but how could I chain method calls on a class when they require a promise to resolve in order to get data. The following will not work as when this.promise is being ...
0
votes
2answers
37 views

Why do I need to use async/await twice in node-postgres

I wrote this code that seems to be working: database.js const {Pool} = require('pg'); const pool = new Pool({ connectionString: process.env.DATABASE_URL, }); module.exports = { query: (text, ...
-1
votes
0answers
37 views

posting form data using fetch and solving 'unexpected token < in json at position 0'

I am trying to post some form data that looks like this when submitted: const formPayload = { company-name: "test" contact-number: "test" email: "[email protected]" event-time: "" event-types: [...
3
votes
3answers
51 views

How to handle catch blocks and then of Promise [duplicate]

I have following code function request(status){ return new Promise((resolve, reject) => { setTimeout(() => { if(status){ resolve('Success'); } else { reject('...
0
votes
1answer
29 views

Using promise to work with web worker inside a JavaScript closure

I was executing an image processing operation in JavaScript which was working as expected expect one thing that sometimes it was freezing the UI, which made me to use Web worker to excute the image ...
0
votes
1answer
37 views

Array from recursive promises returns undefined

I am using Jake Archibald's indexedDB promise wrapper. I have an object store that contains json objects and a separate auto incremented key. When I retrieve the objects i need to also get the key so ...
0
votes
1answer
26 views

NodeJS - Getting 'undefined' while returning values from Promise.all function

I have the following code: var Promise = require('bluebird'); var reqP = Promise.promisifyAll(require('request-promise')); var requestsArray = []; function getRequests(){ const req1 = { ...
0
votes
0answers
27 views

Node's promisify is not working with callback-based function

I am having a function which does some async processing and I want to convert it to a promise, so that I can make a "chain of execution" with other depended functions later on. Below is the code(...
-1
votes
1answer
29 views

ES6 Promise then follows catch but catch never gets called [duplicate]

I have a question about this Promise code. Why "Foo" is logged? I am confused since 'then' is following 'catch', and 'catch' is never called, why execution flows into 'then'? let myPromise = new ...
0
votes
0answers
15 views

Adding promise polyfill and html2canvas into web project

I want to be able to create an image copy of a web page, in order to that, especially in IE11, I need html2canvas.js and a promise polyfill. Clicking on the 'View Image' button should make a copy and ...
-2
votes
0answers
27 views

How to properly return promises in REST application?

I am using FeathersJS to create a HTTP POST endpoint (using the create method in the FeathersJS REST API) and I am having trouble figuring out how to get the code to return value after all my promises ...
-1
votes
0answers
33 views

Recursive promise family tree

I need to make some recursive fetch request in order to render a family tree, based on the data. Each person in the database has a father field which is linked with another person. By making some ...
0
votes
3answers
48 views

What is a ZoneAwarePromise

I am using angular 6. One of the http calls returns a ZoneAwarePromise when I try to convert the Observable into a Promise. Also the then block is not getting called. const login = this.authService....
0
votes
1answer
29 views

How to deal with tuples when returned from an aync function within highland streams?

I use [email protected] and [email protected]^2.13.0. I have an async function that returns a tuple of the type [string, string[]]. I have worked with highland in the past, and I know that I can work with promises ...
2
votes
4answers
71 views

Promise executes then function before previous then execution is completed

I'm try to chain a couple of then functions which execute sequentially, but the last .then() is being executed before the previous is done executing and as a result it sends an empty payload. ...
0
votes
0answers
27 views

Using a Promise with setInterval efficiently

I am still getting used to ES6 Promises, so I’m not sure I’ve worked out the best way of doing things. I have a trivial example which uses setInterval to do something until it has finished. I would ...
-2
votes
0answers
14 views

Save value to outside variable from Promise [duplicate]

I want to return Category name of a product. But outside of then block 'categoryName' is not getting it's value.However if i print 'categoryName' inside then block it is working fine. Is their any ...
1
vote
2answers
49 views

How to solve the pyramid of doom with async/await?

I want to know how to avoid the pyramid of doom of this code: Original code var PlayerService = { getPlayerTeamId: function(playerId, callback) { $.ajax({ url: "/player/" + ...
0
votes
2answers
48 views

Promise and onsubmit

I'm building a form with front-end password hashing: <form action='login.php' method='post' onsubmit='hash(this)'> Password: <input type='password' name='password'><br> <...
0
votes
0answers
24 views

Javascript function returns a promise [duplicate]

I have the following code: export default async function Name(){ var price = await getPrice(id) //get price from a func talking to DB console.log(price) // [object Promise] } async function ...
0
votes
1answer
27 views

Passing through values with nested then statements

I have a function which has the following format: this.callPromiseFunction1(params) .then(results1 => { if (results1.length > 2) { this.callPromiseFunction2(params) .then(...
1
vote
3answers
38 views

Promise.all with promise chain inside

I have a method like this: doSomeRequests(listOfRequestParameters) { let requests = listOfRequestParameters.map(parmeter => { return axios.get(url + parmeter) .then(data => { ...
0
votes
0answers
53 views

async/await return value and odering

If i have the below async function async fn(){ await fn1() // build an updated index from the database let res2 = await fn2() // query the database index res2 = await fn3(res2) // ...
1
vote
0answers
24 views

Set timeout inside an async function with try and catch does not catch error

I have an Ionic 3 App where I use async and await of ES6 features for syntactic sugar of promises. I know this is just a little bit basic question or because I am just new in using async and await ...
0
votes
2answers
61 views

Return value from Promise then callback function

in the following code: function getPosition() { return new Promise((res, rej) => { navigator.geolocation.getCurrentPosition(res, rej); }); } function main() { getPosition()....
1
vote
1answer
72 views

What means a then() returned inside a recursive promise

I have the following code: function someAsyncOperation(){ const myArray = [1,2,3,4,5]; return Promise.resolve(myArray); // return Promise.reject("Reject from someAsyncOperation"); } ...
3
votes
4answers
45 views

Mocha - How to test for unsettled promise?

I am testing a function that returns a promise. I want to assert that, in certain conditions, the returned promise would never settle (doesn't resolve nor reject). How can I test this with Mocha? If ...
1
vote
2answers
63 views

How to wait for multiple asynchronous calls from for loop?

Code without any handling: for (i=0; i<dbImgCount; i++){ (function(i) { imgDownload(FolderPath[i].FolderPath, function (next){ var url = FolderPath[i]....
1
vote
1answer
26 views

Can generator use async functions?

I am fetching data from backend service, 20 results at a time. I would like to hide this implementation detail and create a generator that would keep returning records for as long as I need them (...
0
votes
3answers
63 views

ES6 looping with async call

I need to write some Javascript (ES6 version) to perform the following task: the string is "item1,item2,item3,item4,item5", fetch() an URL using this string. if the response flag is a success, done ...