为什么我的承诺停留在挂起状态,我如何修复它?
var foundPeopleA = findPeopleA().then(function(result) {
var res = []
result.map(function(el) {
res.push(getProfileXML(el.sid));
});
return res
});
var foundPeopleB = findPeopleB().then(function(result) {
var res
我正在看这个来自的代码片段
具体的代码是:
var files = [];
for (var i = 0; i < 100; ++i) {
files.push(fs.writeFileAsync("file-" + i + ".txt", "", "utf-8"));
}
Promise.all(files).then(function() {
console.log("all the files were created");
});
我的问题是,一旦填充了文件,编译器如何知道调用.the
我试图在循环中查询firebase数据,然后需要从那里收集数据,创建数据集合并返回到调用函数。
下面是我的代码,在数组中收集所有结果之前,我无法收集结果并执行返回语句。
function xyz() {
...
// variable lookupKey is defined above this function
return dbRef.child(`/location/${lookupKey}`).once('value').then(contacts => {
const otherUserNotificationids =
我试图对从数据库中获得的列表中的一组项执行异步例程,但我很难理解promise.all是如何工作的以及它是如何工作的。
下面是我现在使用的代码:
/**
* Queues up price updates
*/
function updatePrices() {
console.log("~~~ Now updating all listing prices from Amazon API ~~~");
//Grabs the listings from the database, this part works fine
fetchL
我知道,如果在这样的for循环中有异步等待承诺,它将等待在每次迭代中解析Proceed函数,在最后一个迭代之后,我们可以在for循环下面看到日志:
for(let i = 0; i < guidePack.length; i++){
await Proceed(guidePack[i]);
}
console.log("after for loop"); // we will see this only after all of the Proceeds are resolved
我不知道的是,是否有一个解决方案一次解决所有的承诺,并留下for循环来查看它下
Promise One (resolves in 200ms)
Promise Two (resolves in 400ms)
Promise Three (resolves in 1000ms)
Promise Four (resolves in 300ms)
Promise Five (resolves in 500ms)
这些承诺将按以下顺序解决
0 - Requests Start
100
200 - Promise One
300 - Promise Four
400 - Promise Two
500 - Promise Five (Most recent application
我有3个函数,我想一步一步地调用这个函数,例如,当我调用firs函数并得到结果时,我必须调用第二个函数和第一个调用返回的pass参数。在完成第二次调用之后,我必须调用第三个函数并传递从第二个函数返回的参数。
#1:
getCategory = function (branch_id) {
var deferred = q.defer();
var categoryData;
var query = 'SELECT id,name,price,currency FROM category where branch_id=?';
pool.getC
我有一个链接数组,我想使用解析它的内容,并将结果推到articles数组中。
* parseLinks() {
const links = yield this.getInboxMessages() // It will be ['link1', 'link2', ..., 'linkN']
const articles = []
return new Promise((resolve, reject) => {
for (let link of links) {
mercury.parse(li
我有一个令人费解的情况,我不太明白:
-I有一个由10个对象组成的数组,这些对象具有两个属性:IDNum和imageURL。
-假设这些对象中只有3个实际上拥有它们的imageURL属性集( index positions [0, 4, 9]上的对象),我现在想检索它们的图像。
-I快速地创建了另一个名为imageURLsArray的数组,该数组仅包含这3个URL,我使用.map迭代它,将一个Promise附加到每个数组中-如下所示:
// (there’s a bit of THREE.js code in here - but don’t let that throw you off:
一般来说,我对node.js和javascript并不熟悉,但我对writeFile函数为什么要编写空白文件有问题。我认为for循环应该是一个承诺,但我不知道如何编写它。
const removeProviders = function () {
readline.question('Where is the file located? ', function(filePath) {
let providerArray = fs.readFileSync(filePath).toString().split('\r\n');