promise

Easiest way to wait for google server-side function to resolve

生来就可爱ヽ(ⅴ<●) 提交于 2020-12-12 11:31:07
问题 I need the client side code to wait for the called server side (google.script.run) function to complete before running any more code. The withSuccessHandler(successFunc) does not cause lines of code that are after the server call to wait. What I've done: async function func(){ await google.script.run.withSuccessHandler(myFunc).serverFunc(); console.log("done"); } func(); How can the code wait to execute the console.log line until after the server side function resolves? 回答1: How about this

Easiest way to wait for google server-side function to resolve

依然范特西╮ 提交于 2020-12-12 11:30:31
问题 I need the client side code to wait for the called server side (google.script.run) function to complete before running any more code. The withSuccessHandler(successFunc) does not cause lines of code that are after the server call to wait. What I've done: async function func(){ await google.script.run.withSuccessHandler(myFunc).serverFunc(); console.log("done"); } func(); How can the code wait to execute the console.log line until after the server side function resolves? 回答1: How about this

Async/await inside for…of vs. map

∥☆過路亽.° 提交于 2020-12-12 10:31:30
问题 I'm trying to figure out why promises seem to work differently inside of for...of vs. map() . data is an array of objects of the form {app: MY_APP, link: MY_LINK} . I'm trying to convert it to the form {app: MY_APP, status: true OR false}} . The function checkLink() is async because it uses node-fetch and basically returns whether the given link is 200. Using for...of , I get the desired object: let objToSend = []; for (obj of data) { objToSend.push({ app: obj.app, status: await checkLink(obj

R Shiny promise/future blocks process

心已入冬 提交于 2020-12-12 10:22:11
问题 I cannot figure out the fault in my script's logic that causes Shiny process blocking despite trying to use async future + promises strategy. I have this (simplified) server script. It works in principle, but I don't experience parallelization. I simulate 2 simultaneous triggering and the second triggering event waits until the first one resolves. Can you please indicate what is wrong here? I have read several manuals, but I still find it hard to nail down the logic. Minimal Example, a one

How to trace a failed asynchronous test in Jest?

一世执手 提交于 2020-12-12 06:20:23
问题 - UPDATE - The issue has been identified. In the actual codebase the assertion is passed to a imported callback, and once the callback executes with a failed test, it raises a promise rejection. So, this is close to how the test was actually written: describe( "file system", () => { it( "should check if the file exists", async () => { call( async () => { const received = await fileExists(); const expected = true; expect( received ).toBe( expected ); }); }); }); and the complex callback is

How to trace a failed asynchronous test in Jest?

扶醉桌前 提交于 2020-12-12 06:17:31
问题 - UPDATE - The issue has been identified. In the actual codebase the assertion is passed to a imported callback, and once the callback executes with a failed test, it raises a promise rejection. So, this is close to how the test was actually written: describe( "file system", () => { it( "should check if the file exists", async () => { call( async () => { const received = await fileExists(); const expected = true; expect( received ).toBe( expected ); }); }); }); and the complex callback is

How do I know which handlers throw error in promise?

非 Y 不嫁゛ 提交于 2020-12-11 05:04:24
问题 Suppose I have a promise as following: p.then(Task1) .then(Task2) .then(Task3) .catch(errorHandler); When Task2 encounters error, how do I know the error is from Task2 in catch ? 回答1: everyone! I had researched demonstrated code by myself. I hoped everyone can review my answer, it's good or not. Introduction: It shows how to trace promise in each handler, used customized error handler to catch error. To understand the workflow of promise . You can copy the following demonstrated code and

How do I know which handlers throw error in promise?

无人久伴 提交于 2020-12-11 05:02:53
问题 Suppose I have a promise as following: p.then(Task1) .then(Task2) .then(Task3) .catch(errorHandler); When Task2 encounters error, how do I know the error is from Task2 in catch ? 回答1: everyone! I had researched demonstrated code by myself. I hoped everyone can review my answer, it's good or not. Introduction: It shows how to trace promise in each handler, used customized error handler to catch error. To understand the workflow of promise . You can copy the following demonstrated code and

Why does this readline async iterator not work properly?

有些话、适合烂在心里 提交于 2020-12-10 07:33:12
问题 This is part of a larger process that I've distilled down to the minimal, reproducible example in node v14.4.0. In this code, it outputs nothing from inside the for loop. I see only this output in the console: before for() loop finished finally done The for await (const line1 of rl1) loop never goes into the for loop - it just skips right over it: const fs = require('fs'); const readline = require('readline'); const { once } = require('events'); async function test(file1, file2) { try { const

How to ensure Jest fails on “unhandledRejection”?

岁酱吖の 提交于 2020-12-08 06:46:33
问题 Our unit tests run in containers in our continuous delivery pipelines. Sometimes, we don't handle rejections in our unit tests, however, I don't think it's correct and in my opinion the pipeline should fail. How can I make sure that when I execute jest and during the tests an unhandledRejection event occurs, jest will exit with error? I tried to hook event listeners in a setup script: /* jest.config.js */ module.exports = { setupFiles: ['<rootDir>/test/setup.ts'], // ... } and in that setup