promise

JS: Executing events overlapping in time afteranother

自闭症网瘾萝莉.ら 提交于 2021-01-25 04:02:48
问题 I receive events on-the-fly in the correct order in which I want to process them after another (as well on-the-fly - so don't "store" them first). The following example is not going to work as the function someEventOccured() could be called multiple times in a very close timespan. Thus, the execution of handleEvent would overlap in time (which I don't want). As I am writing to a file in handleEvent() I cannot have simultaneously execute the function and need to maintain the order... async

JS: Executing events overlapping in time afteranother

这一生的挚爱 提交于 2021-01-25 03:59:38
问题 I receive events on-the-fly in the correct order in which I want to process them after another (as well on-the-fly - so don't "store" them first). The following example is not going to work as the function someEventOccured() could be called multiple times in a very close timespan. Thus, the execution of handleEvent would overlap in time (which I don't want). As I am writing to a file in handleEvent() I cannot have simultaneously execute the function and need to maintain the order... async

How to access the aws parameter store from a lambda using node.js and aws-sdk

余生颓废 提交于 2021-01-21 08:36:32
问题 I've created a lambda and cloud formation template which grants a lambda access to the parameter store and secrets manager. When I test the lambda I have the following functions outside of the export.handler function: function getParameterFromStore(param){ let promise = new Promise(function(resolve, reject){ console.log('++ ' + param.Path); servmgr.getParametersByPath(param, function(err, data){ if(err){ reject(console.log('Error getting parameter: ' + err, err.stack)); } else { resolve(data)

How to access the aws parameter store from a lambda using node.js and aws-sdk

半城伤御伤魂 提交于 2021-01-21 08:36:29
问题 I've created a lambda and cloud formation template which grants a lambda access to the parameter store and secrets manager. When I test the lambda I have the following functions outside of the export.handler function: function getParameterFromStore(param){ let promise = new Promise(function(resolve, reject){ console.log('++ ' + param.Path); servmgr.getParametersByPath(param, function(err, data){ if(err){ reject(console.log('Error getting parameter: ' + err, err.stack)); } else { resolve(data)

How to await inside setInterval in JS?

风流意气都作罢 提交于 2021-01-21 03:55:25
问题 I have a code segment that looks like this: async function autoScroll(page, maxDate = null) { await page.evaluate(async () => { await new Promise(async (resolve, reject) => { try { const scrollHeight = document.body.scrollHeight; let lastScrollTop = 0; const interval = setInterval(async () => { window.scrollBy(0, scrollHeight); const scrollTop = document.documentElement.scrollTop; let lastDate = null; if (maxDate) { const html = new XMLSerializer().serializeToString(document.doctype) +

How to await inside setInterval in JS?

孤街醉人 提交于 2021-01-21 03:53:05
问题 I have a code segment that looks like this: async function autoScroll(page, maxDate = null) { await page.evaluate(async () => { await new Promise(async (resolve, reject) => { try { const scrollHeight = document.body.scrollHeight; let lastScrollTop = 0; const interval = setInterval(async () => { window.scrollBy(0, scrollHeight); const scrollTop = document.documentElement.scrollTop; let lastDate = null; if (maxDate) { const html = new XMLSerializer().serializeToString(document.doctype) +

Greater/Less than operator behave differently than equal operator on Q promises

别等时光非礼了梦想. 提交于 2021-01-07 03:30:24
问题 When using Javascript promises, I ran into this weird behavior. Consider the following code: var Q = require('q'); var d1 = Q.defer(); var d2 = Q.defer(); compare(d1.promise, d2.promise); d1.resolve(3); d2.resolve(3); function compare(a, b) { Q.all([a,b]).then(function(results) { console.log('a: ' + a + ' b: ' + b); var result = (a == b)? 1: -1; console.log(result); }); } When you run this code, you get -1. I realize that I am not evaluating the results variable being passed in to the

Execution order of Promises in Node.js

两盒软妹~` 提交于 2021-01-07 03:16:15
问题 I executed following code with Node.js v10.15.0 Promise.resolve() .then(() => console.log('A')) .then(() => console.log('B')) .then(() => console.log('C')) setImmediate(() => console.log('IMMEDIATE')) Promise.resolve() .then(() => console.log('D')) .then(() => console.log('E')) .then(() => console.log('F')) As there is no asynchronous code involved in the fullfilled functions i expected following output A B C D E F IMMEDIATE but i got... A D B E C F IMMEDIATE As far as i understand the

How to make synchronous HTTP request in Angular 8 or 9 (make a request and wait)

六月ゝ 毕业季﹏ 提交于 2021-01-07 02:30:44
问题 There are three buttons: Clicking the first Request HTTP Data As Promise button gets its HTTP response as a Promise . The second Request HTTP Data As Observable button gets its response as an Observable . Both these buttons get their responses using asynchronous response mechanism. Now, I would like the third Request HTTP Data and Wait button to get a synchronous response. I would like it to wait for the http service to return the HTTP response. How could it be done? Here is the link to the

How to make synchronous HTTP request in Angular 8 or 9 (make a request and wait)

爷,独闯天下 提交于 2021-01-07 02:28:10
问题 There are three buttons: Clicking the first Request HTTP Data As Promise button gets its HTTP response as a Promise . The second Request HTTP Data As Observable button gets its response as an Observable . Both these buttons get their responses using asynchronous response mechanism. Now, I would like the third Request HTTP Data and Wait button to get a synchronous response. I would like it to wait for the http service to return the HTTP response. How could it be done? Here is the link to the