rsvp.js

How to read multiple files asynchronously with promises, then proceed

你离开我真会死。 提交于 2019-12-03 15:09:35
I'm new to promises and using the rsvp implementation. I want to asynchronously read a list of files, then proceed to another task only when all files have been read. I've got as far as the basic structure to read one file, and chain to the next task: var loadFile = function (path) { return new rsvp.Promise(function (resolve, reject) { fs.readFile (path, 'utf8', function (error, data) { if (error) { reject(error); } resolve(data); }); }); }; loadFile('src/index.txt').then(function (data) { console.log(data); return nextTask(data); }).then(function (output) { //do something with output }).catch

Are Promise.resolve and new Promise(resolve) interchangeable

爱⌒轻易说出口 提交于 2019-12-01 06:56:24
I think Promise.resolve and new Promise(resolve) are interchangeable. Consider this: A. new RSVP.Promise(function (resolve, reject) { resolve(); }).then(function () { return new RSVP.Promise(function (resolve) { resolve("HI") }); }).then(function (result) { console.log(result); }); B. new RSVP.Promise(function (resolve, reject) { resolve(); }).then(function () { return RSVP.resolve("HI"); }).then(function (result) { console.log(result); }); Both print "HI" as I expected. So I think if I don't need to "reject" anything. I can just write RSVP.resolve(); for simplicity. But consider this example:

acceptable promise pattern for 'LOUD' errors?

时间秒杀一切 提交于 2019-11-30 06:01:12
问题 I'm using the RSVP library distributed inside Ember.js and I'm trying to figure out the correct pattern for reporting fatal errors inside a promise -- particularly I want to inform of something that's almost certainly the result of a programming error due to api misuse and I want to do it in a LOUD way. I'm new to promises and javascript in general, hopefully this question makes sense Here's a simple example (in coffeescript): doAsync = (arg, callback) -> throw new Error('you gave me a way

acceptable promise pattern for 'LOUD' errors?

 ̄綄美尐妖づ 提交于 2019-11-28 12:34:29
I'm using the RSVP library distributed inside Ember.js and I'm trying to figure out the correct pattern for reporting fatal errors inside a promise -- particularly I want to inform of something that's almost certainly the result of a programming error due to api misuse and I want to do it in a LOUD way. I'm new to promises and javascript in general, hopefully this question makes sense Here's a simple example (in coffeescript): doAsync = (arg, callback) -> throw new Error('you gave me a way bad arg, I fail for you!') promiseReturningApi = (data) -> return new Ember.RSVP.Promise (resolve, reject

Promise chain continues before inner promise is resolved

瘦欲@ 提交于 2019-11-27 09:50:34
Similar question to Promise resolve before inner promise resolved but I can't get it to work nontheless. Every time I think I understand promises, I prove myself wrong! I have functions that are written like this function getFileBinaryData () { var promise = new RSVP.Promise(function(resolve, reject){ var executorBody = { url: rootSite + sourceRelativeUrl + "/_api/web/GetFileByServerRelativeUrl('" + fileUrl + "')/$value", method: "GET", binaryStringResponseBody: true, success: function (fileData) { resolve(fileData.body); }, error: function (argument) { alert("could not get file binary body")

Promise chain continues before inner promise is resolved

╄→гoц情女王★ 提交于 2019-11-26 14:54:20
问题 Similar question to Promise resolve before inner promise resolved but I can't get it to work nontheless. Every time I think I understand promises, I prove myself wrong! I have functions that are written like this function getFileBinaryData () { var promise = new RSVP.Promise(function(resolve, reject){ var executorBody = { url: rootSite + sourceRelativeUrl + "/_api/web/GetFileByServerRelativeUrl('" + fileUrl + "')/$value", method: "GET", binaryStringResponseBody: true, success: function

How can I execute array of promises in sequential order?

走远了吗. 提交于 2019-11-26 12:09:39
I have an array of promises that need to run in sequential order. var promises = [promise1, promise2, ..., promiseN]; Calling RSVP.all will execute them in parallel: RSVP.all(promises).then(...); But, how can I run them in sequence? I can manually stack them like this RSVP.resolve() .then(promise1) .then(promise2) ... .then(promiseN) .then(...); but the problem is that the number of promises varies and array of promises is built dynamically. If you already have them in an array then they are already executing. If you have a promise then it's already executing. This is not a concern of promises

EmberJS: How to load multiple models on the same route?

╄→尐↘猪︶ㄣ 提交于 2019-11-26 00:14:09
问题 While I am not new to web development, I am quite new to to client-side MVC frameworks. I did some research and decided to give it a go with EmberJS. I went through the TodoMVC guide and it made sense to me... I have setup a very basic app; index route, two models and one template. I have a server-side php script running that returns some db rows. One thing that is very confusing me is how to load multiple models on the same route. I have read some information about using a setupController