Implement promises pattern

I have a function that called with other objects and when my application is loaded, get parameter and the function should wait for call with all of object and then execute so with promises pattern i can ensure all object is loaded but i don't know about count of object and i don't want set timeout for loading.I don't talk about specific technology such as jquery and need algorithm.

实施承诺模式

我有一个函数调用其他对象,当我的应用程序被加载,获取参数和函数应该等待与所有的对象调用,然后与承诺模式执行,我可以确保所有的对象被加载,但我不知道计数的对象,我不想为加载设置超时。我不谈论具体的技术,如jquery和需要算法。 伪代码: function loadWidget(id){ list.push(id); //here I should ensure all Widget is loaded } 在我打电话的其他应用中 app.loadWidget.add

function will return null from javascript post/get

New to JavaScript, and just started to read about Callback and Promise. I just don't understand the concept of "wait" until I have a value from a POST/GET request. More specific, why won't this work? var token = null; / / var options = {headers, form, etc} / function getToken() { request(options) .then(function (parsedBody) { this.token = parsedBod

函数将从javascript post / get返回null

JavaScript新手,刚开始阅读关于Callback和Promise的内容。 我只是不明白“等待”的概念,直到我有来自POST / GET请求的值。 更具体地说,为什么不能这样工作? var token = null; / / var options = {headers, form, etc} / function getToken() { request(options) .then(function (parsedBody) { this.token = parsedBody }) .catch(function (err) { console.l

Promise.all in Node is undefined

I'm playing around with promises in Node.js and am trying to use Promise.all. I'm pushing three functions that return a promise into an array and then calling Promise.all but the all's resolve is never hit. On the debugger, it also says that Promise.all is "undefined". Why is Promise.all never returning and why does it show up as "undefined"? Relevant part of

Promise.all在Node中是未定义的

我正在玩Node.js中的承诺,并试图使用Promise.all。 我推送了三个函数,它们将一个承诺返回给一个数组,然后调用Promise.all,但所有的决心都不会被触发。 在调试器上,它也表示Promise.all是“未定义的”。 为什么是Promise.all从不返回,为什么它显示为“未定义”? 代码的相关部分: var updates = []; updates.push(data.updateItemCondition(characterID, specificItemID_toUse, newCondition)); updates.push(data.updat

Promise.all in JavaScript: How to get resolve value for all promises?

I wrote the following node.js file: var csv = require('csv-parser'); var fs = require('fs') var Promise = require('bluebird'); var filename = "devices.csv"; var devices; Promise.all(read_csv_file("devices.csv"), read_csv_file("bugs.csv")).then(function(result) { console.log(result); }); function read_csv_file(filename) { return new Promise(function (resolve, reject) { var

Promise.all在JavaScript中:如何获得所有承诺的解决价值?

我写了下面的node.js文件: var csv = require('csv-parser'); var fs = require('fs') var Promise = require('bluebird'); var filename = "devices.csv"; var devices; Promise.all(read_csv_file("devices.csv"), read_csv_file("bugs.csv")).then(function(result) { console.log(result); }); function read_csv_file(filename) { return new Promise(function (resolve, reject) { var result = [

How can I chain these functions together with promises?

This is a program that scrapes the data out of a tshirt website and then writes the product info to a CSV file. There are 3 scrape functions and 1 write function. Right now, I am having an absolute nightmare trying to get my head around how to implement promises here without any 3rd party libraries or packages. Is this possible with just the native features of ES6? Due to the async nature

我如何将这些功能与承诺一起链接起来?

这是一个从t恤网站中删除数据然后将产品信息写入CSV文件的程序。 有3个刮擦功能和1个写入功能。 现在,我有一个绝对的噩梦试图让我的头在如何实现承诺这里没有任何第三方库或包。 这可能与只有ES6的本地功能? 由于请求的异步性质,我需要每个函数及其请求在下一个请求被调用之前完成。 这是因为我可以在下一个函数中使用urlSet等变量。 我怎样才能做到这一点,而不重写我的整个代码? 我应该提到,这些功能中的每一

How can i return status inside the promise?

I started to learning promise with loopback and jsforce, and couldn't handle this problem; I couldn't return status var inside promise to cb() function. Basically i want to connect salesforce and get data via JSforce and write it to db via loopback. Then want to return created/updated/error records to client after remote mothed called. I'm developing with Loopback via using Node.

我如何返回承诺内的状态?

我开始学习使用loopback和jsforce的promise,并且无法处理这个问题。 我无法将状态变量返回给cb()函数。 基本上我想连接salesforce并通过JSforce获取数据并通过回送将其写入数据库。 然后想要在远程调用后调用创建/更新/错误记录到客户端。 我正在使用Node.JS&Express.js通过Loopback进行开发。我正在使用JSforce库来连接salesforce 我该如何解决这个问题? 这是我的代码: module.exports = function(Contact) {

Exporting Node module from promise result

I'm trying to rewrite a module to return a different value than before, but now it uses an async call to get that value. (with child_process if it matters). I've wrapped it in a Promise, but that's not critical to me - it can be in the original child_process callback, but the problem is I can't chain the promise to everywhere in the app because I need this to become synchronous.

从诺言结果中导出节点模块

我试图重写一个模块以返回与以前不同的值,但现在它使用异步调用来获取该值。 (如果有关系,使用child_process )。 我已经将它包装在一个Promise中,但这对我来说并不重要 - 它可以在原始的child_process回调中,但问题是我无法将承诺链接到应用程序中的任何地方,因为我需要将它变为同步。 这是我的模块: exec = require('child_process').exec platformHome = process.env[if process.platform is 'win32' then 'USERPR

Return Promise result instead of Promise in Nodejs

Background I am trying to learn promises, and I have a promise chain I want to improve on. Problem While learning how to chain promises, I fail to see why anyone would rather return a promise instead of returning it's value. Take the following example, which uses promise chaining: let myObj = new MyClass(); myObj.getInfo() .then(result => writeOutput(FILE_NAME, result)) .

在Nodejs中返回Promise结果而不是Promise

背景 我正在努力学习承诺,并且我有一个我想要改进的承诺链。 问题 在学习如何链接承诺的同时,我不明白为什么有人愿意回报承诺而不是回报它的价值。 以下面的示例使用promise链: let myObj = new MyClass(); myObj.getInfo() .then(result => writeOutput(FILE_NAME, result)) .then(console.log(FILE_NAME + " complete")) .catch(error => console.error(error)); class MyClass{ getInfo(

promise call separate from promise

I'm not so familiar with promises. I would like hide promise-implementation from promise-call. Example: function findFriends(req, res) { const promiseFriend = MyFriendes.find({}).exec(); //call promise if(friends.length===0){ logger.warn('No friendsavailible'); }else if(friends === undefined){ res.status(500).json({ error: 'INTERNAL ERROR'

承诺与承诺分开

我不太熟悉承诺。 我希望隐藏诺言 - 诺言的实现。 例: function findFriends(req, res) { const promiseFriend = MyFriendes.find({}).exec(); //call promise if(friends.length===0){ logger.warn('No friendsavailible'); }else if(friends === undefined){ res.status(500).json({ error: 'INTERNAL ERROR' }); }else{ res.status(200).json({

Should I refrain from handling Promise rejection asynchronously?

I have just installed Node v7.2.0 and learned that the following code: var prm = Promise.reject(new Error('fail')); results in this message:; (node:4786) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: fail (node:4786) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate th

我是否应该避免异步处理Promise拒绝?

我刚刚安装了Node v7.2.0,并了解到以下代码: var prm = Promise.reject(new Error('fail')); 导致此消息:; (node:4786) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: fail (node:4786) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit