rsvp.js

Promise chain continues before inner promise is resolved

て烟熏妆下的殇ゞ 提交于 2020-01-06 21:49:06
问题 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 do I return the boolean value from this layer-cake of promises?

穿精又带淫゛_ 提交于 2019-12-23 20:57:14
问题 I've got a controller method that takes a string argument so I can test if a user has a capability. The user has many roles and the roles has an array of permissions attached that we need to check if it contains the capability. I know this is overly verbose, but for the sake of understanding, I've left it so. Will refactor later... App.WorkspaceIndexController = Ember.Controller.extend({ userCan: function(capability) { var userHasCapability = false; var userPromise = this.get('session.user');

Trying to understand Ember JS promises

爷,独闯天下 提交于 2019-12-21 09:07:56
问题 I have been trying to work on a code example to get my head around promises. But I can't seem to figure out how to deal with the callbacks and get the "thenable" value later. Here are two relevant JSBin examples I am working on. Written in verbose style to emulate baking cookies. Ember JS without async http://jsbin.com/iSacev/1/edit purely synchronous example to show the basic behavior (deliberately using basic object model) Ember JS with async and promises http://jsbin.com/udeXoSE/1/edit

How to read multiple files asynchronously with promises, then proceed

喜欢而已 提交于 2019-12-21 04:55:23
问题 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) {

Are Promise.resolve and new Promise(resolve) interchangeable

旧时模样 提交于 2019-12-19 03:54:28
问题 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

How can I execute array of promises in sequential order?

血红的双手。 提交于 2019-12-17 02:35:06
问题 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. 回答1: If you already have them in an array then they

Ember.RSVP.all seems to resolve immediately

你。 提交于 2019-12-13 18:50:17
问题 I'm really hoping that there's something dumb that I'm doing, but I can't seem to find it. I'm trying to use Ember.RSVP.all in the middle of a chain of promises. The example I have is much simpler than my use, but it demonstrates the issue. In the middle of a chain of promises, I have a set of promises that all need to resolve before the chain can continue - exactly what I understand RSVP.all to be for. Unfortunately, when I return the RSVP.all object, the next promise in the chain runs

RSVP - Handling timeouts with promises

a 夏天 提交于 2019-12-12 12:03:48
问题 I am using ember.js and RSVP. From what I can see, there is nothing that handles a timeout from an async call. My thinking is to wrap the resolve handler using the decorator pattern to wrap the resolve handler in some code that will time the call and call reject if the timeout happens. Does this sound like a good idea or is there some built in support for timeouts that I have missed in RSVP. 回答1: You can do that, but this should probably be handled by whatever is doing the async operation. If

Angular POS Print Issue

别等时光非礼了梦想. 提交于 2019-12-11 11:37:18
问题 My requirement: Print without print preview angular 6 Only solution i found Angular 2 Raw Printing Service I am using think link for Angular POS print Do i have any other alternatives? .ts code printInvoice() { console.log(this.printService.getPrinters()); } My Service code import { Observable } from 'rxjs'; import 'rxjs/add/observable/fromPromise'; import 'rxjs/add/observable/throw'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; import { Injectable } from '@angular/core';

How to use Ember.RSVP.onerror to report exceptions from rejected promises without error handlers

十年热恋 提交于 2019-12-05 22:17:29
问题 I just watched this video of a recent panel discussion with the ember-core framework developers. In the video the panel members are eached asked to share one general debugging tip -- Tom Dale calls out the RSVP onerror handler which makes it possible to globally report exceptions which would have otherwise been swallowed in promises without rejection handlers. I think this handler will answer a (somewhat confused) question I asked elsewhere on Stack Overflow. Does anyone know how to use this