Questions tagged [promise]

Promises are a tactic for deferred computing, suitable for several styles of concurrency: thread and event loop concurrency for local computation, and both synchronous and asynchronous remote messaging. A promise represents the eventual result of an asynchronous operation. The primary way of working ...

0
votes
0answers
3 views

firebase transactions you must return a promise

I am trying to figure out how to write transactions to a firebase database from an angular 6 / typescript application. One working example I am using as a guide is the following: const transactions =...
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
0answers
14 views

How does promise linking work in Scala and why is it necessary?

I found some some articles and the source code of Scala's futures and promises: https://viktorklang.com/blog/Futures-in-Scala-2.12-part-9.html https://github.com/scala/scala/blob/2.13.x/src/library/...
1
vote
1answer
25 views

Single async function that makes multiple fetches and returns results?

I am attempting to write an async function that makes multiple fetches, waits for all to complete, then returns the JSON results as an array. This is what I have so far: file1.js const searchResults ...
1
vote
1answer
15 views

Observable chaining, flatMap and type casting

I'm new to observables and I want to learn. I have an API.get() method that returns a promise of type T as T is: export interface T { data?: object; errors?: [object]; extensions?: { ...
0
votes
0answers
21 views

Promise Jump Alwasy to The catch

I have an async function (a Promise) which does some things. I have to call it N times. Every call represents a simulation point. My first guess was to use a loop: for(let i=0; i < N; i++) { ...
0
votes
0answers
23 views

Make sync function in node js

Here is my function: I want summaryArr to load value and only then i want to execute the further code. As you can see i am using map and recursion in my function. Please help. function ...
0
votes
1answer
12 views

Run N Promises with parallel limitation

So, I am trying to run N promises with parallel count limitation. I want to have for example 3 promises waiting callback while my program works. Not more, but still could be a situation, when 2 ...
0
votes
0answers
14 views

return Promise every time when event is emitted [duplicate]

Hi Guys how can i return a promise every time when event is emitted code is below: connect() { return new Promise( ( resolve, reject ) => { this.wss.on( '...
0
votes
0answers
22 views

groovy grails async promise execute immediately

In the below code, inside controllerMethod , onComplete event execute immediately without waiting for the finishing of promiseList in the callApisInParallel method in groovy/grails import grails....
0
votes
1answer
41 views

Wait for async recursive function to complete before proceeding to next line of code

I am trying to wait for a recursive function to fully complete before proceeding to next line of code. I am using PuppeteerJS to look for an item on a page and if the item does not exist, after 3 ...
0
votes
0answers
7 views

Login to website using Request-Promise and Cheerio - node.JS

I'm attempting to scrape some data from ESPN's fantasy football, but in order to do so I need to sign in here. I'm very new to this API and in general a rookie programmer, so can anyone point in me in ...
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
0answers
11 views

Accessing the Values with a Promise in Javascript [duplicate]

I am trying to fetch some data and then access the values in the response but I keep running into Promise which I can't seem to get out of to access my values. Here is my request: var boom = fetch(...
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
3answers
35 views

Looping with Promises in JS

I am trying to run queries inside a for loop in nodejs and each iteration of the for loop runs one query. The queries are done with a "get()" method that returns a Promise. In my function (that ...
0
votes
3answers
38 views

How to wait for iteration to complete before returning

I am trying to loop through an Array of JSON objects (var requestArray = req.body;, specifically requestArray['filter']), persisting each object into a database. After each persistence, I pull the ...
0
votes
1answer
14 views

MPMediaQuery wait until Media dialog is complete before callback

My goal is to establish a bridge between iOS and react-native and return back all the podcast titles. The bridge seems to be working, and the podcast titles get returned however the callback I've set ...
0
votes
1answer
32 views

Ho do know that document.createElement('img') will be completed sync?

I'm trying to understand async/await and stuck with problem in example. I know that if i have 2 functions like: f1(//console.log(1) after 5 sec) f2(//console.log(2) after 1 sec) result will be: 2 ...
0
votes
1answer
34 views

React Native Android - Promise.all throws [TypeError: [object Object] is not iterable!] for an array of promises

I'm using react native and expo. I have this code: const a = {}; const promises = []; someArray.forEach(c => { a[c] = { ref: firebase.ref(`someref/${c}`), data: null } ...
0
votes
1answer
28 views

cloud functions notifications for android

I was trying to send notifications to multiple users with cloud functions of firebase for an android app Here is what I did. exports.sendNotification = functions.database.ref('/notifications/...
1
vote
6answers
52 views

Angular call function with promise in typescript

I have 3 functions. And I want to call the other function after a function is completed. In my first function, I am setting a variable(students) in the page. And the second function uses that variable....
0
votes
2answers
37 views

NodeJs - How do I return response with a list of msg after the for loop is completed

I am using nodejs. How do i ensure that my for-loop completely finished running, so that i can return my msgList which is populated with records of which one pass/fail? Is there a proper way if ...
0
votes
1answer
23 views

What's the difference between Promise.reject an error and Promise.reject object?

I was reading some nodejs tutorial which talks about rejection in nodejs. They say that it's best practice to reject an error instead of a string or an plain text. Taking example of this code. This ...
0
votes
3answers
27 views

jQuery loading layout before adding change events

Basically I have two functions, loadLayout and saveLayout. loadLayout needs to load first so that I can apply a .change() event to elements that it loads, so when they are changed saveLayout is fired....
0
votes
1answer
28 views

Using promises in React to wait for functions to finish within JavaScript map function

I've been trying to figure out what the proper way would be to write a promise for this function. I have an asynchronous function that makes an HTTP request to the server to retrieve a response, "...
-1
votes
1answer
21 views

UnhandledPromiseRejectionWarning: undefined in Mongoose

When trying to authenticate users with Mongoose I get the following warning in my console: (node:20114) UnhandledPromiseRejectionWarning: undefined (node:20114) UnhandledPromiseRejectionWarning: ...
0
votes
2answers
51 views

How to wait for promises to complete within the onchange event using JavaScript?

I have a need to manually trigger the change event on a menu. But then I need to wait until change event complete execution then I would perform action. Here is what I am trying to do in code $('#...
0
votes
2answers
35 views

How to write a counter with sync interface for async code, using only the native Promise?

I want to create an object that exposes the following interface: // Create the object that counts to three const c = counter(3); // c.finished is a promise that resolves when c.count() is invoked ...
1
vote
1answer
14 views

Jest unresolved promise do not fail

Jest docs says: Unresolved Promises If a promise doesn't resolve at all, this error might be thrown: (and so on) In my case this not happen. I have this test: test('detect infinite loop', ()...
1
vote
2answers
51 views

Is there a way to end a thenable chain?

let textProcess = new Promise((resolve, reject) => { let text try { // fetch text from the internet text = "str" resolve(text) } catch (e) { reject("...
1
vote
2answers
71 views

Angular 5 wait for promises to return from for loop

I have the array as below: arr = ['res1', 'res2', 'res3']; Then for each arr value, I will do an API call that will return a promise arr.forEach(val => this.getPromise(val)); The method ...
0
votes
1answer
21 views

Nested promise catch not executing [duplicate]

I have a function which takes a function that returns a Promise and I am calling it like so: const test = (prom) => { prom() .then(() => console.log('top level then')) .catch(() => ...
0
votes
1answer
25 views

node.js express promise router error handling wrapper

I'm trying to create an error handling wrapper to use with the promise router extension of express in nodejs. For starters, I try to simply wrap the async handler function: function error_catcher(f) ...
0
votes
1answer
40 views

javascript promises inside array

I am working on a simple task where I have an array of shapes like square and rectangle and there sizes as another array passed as a parameter to function called findAllObjectArea. I want to return a ...
-2
votes
1answer
19 views

Javascript promise fail to catch timeouts or 500 server error

I am trying to use javascript Promise to call a function multiple times. The function actually calls an URL and gets json object back. I get the json object back properly when the call is success. If ...
0
votes
2answers
35 views

Sync vs Immediate Async execution performance bench

I'm interested in performance comparison of synchronous and asynchronous data conversion test in case if async function would return result immediately. Will this affect on execution time? To check ...
1
vote
2answers
30 views

Convert Promise to Observable in ngrx Effect

I'm using third party library which give promises, but i need to wrap it to Observable in ngrx effect. The idea is to dispatch new action when app is initialized successfully. But i need to dispatch ...
0
votes
0answers
28 views

Vuex function execute before the other

I am using Vue + Vuex to delete the user token from localStorage to make the user logout and redirect them to login page. Component logout method Code: methods: { logout () { this.$...
0
votes
3answers
67 views

How to wait until 2 $http requests end in angularjs

I need to process responses of two different $http requests. What is the best way to do so, knowing that I have to wait for answers of both request before to process their results. I think I must use ...
0
votes
2answers
32 views

Linking users and avatar urls to each other within same promise

need some help. From firebase I collect all my users I get an object array containing key value pairs. To this object I want to add another key value pair: avatarUrl: 'someurl' Then I want to ...
0
votes
1answer
41 views

How to obtain the result of a transaction in the Firebase database?

I'm trying to get the result of an update operation on a node of the Firebase Database, working with Angular2. This method is executed in a service class called arbitro.service.ts. This class has a ...
0
votes
1answer
27 views

Angular Promise Conditional

My Angular v1.x directive calls a function when a button is clicked and depending on the input I set some variables: $scope.offerRespond = function() { if (offer.i.offerResponse == 1) { ...
0
votes
0answers
16 views

Call Same API Multiple times with param in react-redux

redux to do advance search. I have this search page how it look likes: Default Search Page This is my SearchAction. SearchAction.js export const GET_PROVIDER = 'GET_PROVIDER'; export const ...
0
votes
0answers
13 views

Not able to return a value from an async function in Node.js [duplicate]

I am trying to read 2 fields from the firebase DB by using the below code: const policyType = readFromDb('policyType'); const claimCategory = readFromDb('claimCategory'); This is what the readFromDb(...
0
votes
4answers
40 views

How to pass a parameter for a JS function inside .then, or achieve similar behavior?

Let's assume there is a promise createPost and a function getPosts. The first one creates a recored in a database of posts and resolves. getPosts retrieves all posts, creates a UL lists and appends it ...
2
votes
1answer
39 views

Attach a callback on click of a button which does an ajax operation

I'm aware that this can be achieved via a Promise but I am struggling to figure out how. jQuery('.parentDiv').on('click', '.link', function(e) { jQuery.when(jQuery('.saveBtn').trigger('click', { '...
0
votes
1answer
25 views

\React\Promise\all($promises) doesn't work as expected in ReactPHP

Please note that I've also created an issue on the related repo. In the documentation, it says that this function will return a promise which will resolved after all the promises in the array have ...
0
votes
1answer
40 views

Adding a parameter to a function in .then() breaks the behaviour of a promise in JS [duplicate]

getPosts() loops through an array of posts, builds LIs and places them inside document.body. Works ok. function getPosts(num){ let output =''; posts.forEach((post, index)=>{ output += `&...
0
votes
0answers
37 views

Is there any global error handles for Promises [duplicate]

Any error occurring inside Promise is silent if I dont have try/catch or use .catch() after then() function. In angularJS there is a Service $q which handles promises but any error occuring inside ...