es6-promise

assign resolve values to global variables - promises [duplicate]

白昼怎懂夜的黑 提交于 2020-08-26 13:49:08
问题 This question already has answers here : How do I return the response from an asynchronous call? (39 answers) Closed 3 years ago . Rather than use callbacks, I decided to use promises. I resolve the variable which holds a price and then I call .then to handle it like this. SomeAsyncThing("fifa 17").then(function(value){ console.log("value " + value); }); How can I assign the value to a global variable to use elsewhere in JS? Am I missing something obvious? I've tried defining x = 0; at the

How to destructure results of a dynamic number of async calls with Promise.all

怎甘沉沦 提交于 2020-08-08 06:24:41
问题 I need to make an unknown number of async calls in parallel via Promise.all . Something similar to this: let externalCalls = [call1()]; if (someCondition1) { externalCalls.push(call2()); } if (someCondition2) { externalCalls.push(call3()); } Then externalCalls will be passed to Promise.all so they can be run in parallel. Ideally, I'd like to use destructuring of the results so that I can refer to results by name, i.e. const [call1, call2, call3] = await Promise.all(externalCalls); I know

Electron: dialog.showOpenDialog not returning a promise?

巧了我就是萌 提交于 2020-07-06 11:23:29
问题 I would like to show an Open Dialog box from within a rendered script. I am getting conflicting information from different sources, but, as far as I can tell, the documentation at https://electronjs.org/docs/api/dialog suggests I should be able to use: const dialog = require('electron').remote.dialog; dialog.showOpenDialog({ title: '…', defaultPath: '…' }) .then(data=>console.log(data)); The error message I get is: TypeError: dialog.showOpenDialog(...).then is not a function That suggests

Electron: dialog.showOpenDialog not returning a promise?

╄→гoц情女王★ 提交于 2020-07-06 11:23:20
问题 I would like to show an Open Dialog box from within a rendered script. I am getting conflicting information from different sources, but, as far as I can tell, the documentation at https://electronjs.org/docs/api/dialog suggests I should be able to use: const dialog = require('electron').remote.dialog; dialog.showOpenDialog({ title: '…', defaultPath: '…' }) .then(data=>console.log(data)); The error message I get is: TypeError: dialog.showOpenDialog(...).then is not a function That suggests