Async await of a promise

I have to wait to func1 to be termined to run func2. But Since func1/2/3 contains promises it prints "termined" to early. async function executeAsyncTask () { const res1 = await func1(a,b,c) const res2 = await func2(a,b,c...
more »

2017-11-30 18:11 (4) Answers

Why is this not a memory leak?

I am interested in using a generator + promise pattern where the promise will iterate through the generator, resolve each yielded value, and pass it back into the generator. Once it's done, the promise resolves with the final return (if any). I foun...
more »

2017-11-27 19:11 (0) Answers

The proper ways to stack optioned promises

What would be the proper or the best way to collect all data from DB with promises, but with using native Node promises. The goal is only to present what is selected: const allPromises = []; const selected = { sectionA: true, sectionB: false, ...
more »

2017-11-24 10:11 (3) Answers

Return an array from a function with a promise

I need to return the array lotSpecItems from this function once it is populated: public getLotSpecItems(id: number) { let toReturn = this.resourceClass.getLotSpecItems({ lotId: id }); let lotSpecItems = []; return toReturn.$promise.then(...
more »

2017-11-21 23:11 (1) Answers

DRY Then and Always in jQuery Promise

I have the following example JS code: function loadData(url, data) { return $.get(url, data ? data : {}); } function example1() { showSpinner(); $.when(loadData('/example1', { hello: 'world' })) .then(function (resp) { ...
more »

2017-11-14 11:11 (3) Answers

Async function versus return New Promise

UPDATE I have read over a dozen articles on this topic and not one of them addresses this fundamental question. I am going to start listing a resources section at the end of this post. ORIGINAL POST My understanding of an async function is it ret...
more »

2017-11-01 04:11 (1) Answers

what happens when a Promise never resolves?

I have this very confusing snippet of code using es6 async await syntax. What I would expect to happen is that the process hangs on the await line forever, since the resolve function is never called. However, what actually happens is that "start" is ...
more »

2017-10-27 05:10 (2) Answers

How to use promises correctly?

I have a sharepoint form where the user fill some textboxes. The user click on the save button. The script run from here. Check if all texbox is filled or not. If good, get some fields from an outer list based on the inputs and update some other lis...
more »

2017-10-19 10:10 (1) Answers

How to check if file exists from url with angular?

I'm working on a hybrid mobile app based on Ionic -v1 / Cordova and I would like to know the best practices for this. So far I found an option with the fetch function in the controller function: angular.module('my.controllers') .controller('myCtrl'...
more »

2017-10-17 10:10 (1) Answers

Node.js Promise reference error

I'm getting a reference error saying check is not defined when I call check().then(function(employees) towards the bottom of my code and I;m not sure why. This happens when I call getAllEmployees(); var employees = []; var departments = []; var err...
more »

2017-10-01 23:10 (3) Answers

Passing another promise to a promise handler

I expected the promise handler to log the promise p1 (not the value "A") since console.log is called with p1 directly. However, it somehow logs "A". How is the promise p1 automatically resolved to "A" without then being called on it ? For example, co...
more »

2017-09-29 16:09 (2) Answers

Angular Anchor Scroll without Promise

I have am trying to use a very simple scrollTo in Angular 1.x. I have naviagation menu link which when clicked should scroll to a div#id. I can only get this to work with a 'promise'. For example, this works: <li><a href="#" ng-click="trac...
more »

2017-09-16 12:09 (2) Answers

promise reject not working with mysql error

I am trying to get return an mysql data using promises and it works, but when I try to create an error in mysql on purpose but then I am getting this error . (node:28464) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1...
more »

2017-09-09 17:09 (1) Answers

Extending Promise to support Progress reporting

So I wanted to extend Promise to have a 'progress' part so that i can report progrss with it while using Promise for my Async tasks. Thus I extended Promise like this: class promisePro extends Promise { constructor(fn) { super(function ...
more »

2017-09-03 08:09 (1) Answers

How to chain promises on reject

Given a function, fn, which returns a promise, and an arbitrary length array of data (e.g. data = ['apple', 'orange', 'banana', ...]) how do you chain function calls on each element of the array in sequence, such that if fn(data[i]) resolves, the who...
more »

2017-09-02 02:09 (5) Answers

Javascript Promise Function Style

Suppose I have a function that will return a promise that is based on some input value that need to be calculated first. It seems that there are two ways to do this. Example 1: function foo(val) { var newVal = val + 100; var anotherVal =...
more »

2017-07-27 23:07 (2) Answers

Angularjs how to get filename extension?

Hi I am developing angularjs application. I am doing file upload module. I am trying to validate the files. I want to upload only xlsx or xls files. I have developed directive and factory method to upload files as below. myapp.directive('fileModel',...
more »

2017-07-18 10:07 (3) Answers

How does switchMap() resolve a Promise?

I am going through the Angular 2 tutorial and I'm on the part about routers, specifically the part about using an Observable to extract the parameters from a URL. It uses Observables for this. Part of the code is this: ngOnInit(): void { t...
more »

2017-06-27 17:06 (1) Answers