chaining

$q.reject and handling errors in AngularJS chained promises

别来无恙 提交于 2019-11-30 20:26:35
I'm having trouble understanding a basic concept of error handling with chaining promises. In order to learn the rules, I have written a simple example, guessing what the result will be. But unfortunatly it doesn't behave as I though it will. I have read multiple articles about the subject but perhaps can't I get details because of my poor english language. Anyway, here is my code : var promiseStart = $q.when("start"); var promise1 = promiseStart.then(function() { return Serviceforpromise1.get(); }); var promise2 = promise1.then(function(data1) { return Serviceforpromise2.get(data1); }

jQuery ajax call chaining with multiple dependencies

荒凉一梦 提交于 2019-11-30 19:17:43
问题 I don't quite understand magic deferred objects with jQuery. Assume the following code: function callWebService(uri, filter, callback) { var data = {}; if (filter && filter != '') data['$filter'] = filter; jQuery.ajax({ url: '/_api/lists/' + uri + '/items', data: data, success: callback, dataType: 'json' }); } function getInitialData() { callWebService("InitialData", "", function (data) { //do stuff with data }); } function getGreenData() { callWebService("GreenData", "filter from InitialData

How to chain checks in java

天涯浪子 提交于 2019-11-30 18:57:59
问题 Consider a class like the following public class MyClass { private Integer myField; private Result result; // more global variables public MyResult check(Integer myParameter) { init(myParameter); if (myField < 0) { result.setErrorMessage("My error message"); return result; } // a lot more 'checks' like above where something may be written // to the error message and the result gets returned. } private void init(Integer myParameter) { result = new Result(); result.setExistsAnnouncement(/

Underscore.js _.tap() function what is a method chain?

荒凉一梦 提交于 2019-11-30 17:25:07
问题 The Underscore.js documentation explains that the _.tap() function "taps" into a method chain. http://underscorejs.org/#tap I have trouble following their example: _.chain([1,2,3,200]) .filter(function(num) { return num % 2 == 0; }) .tap(alert) .map(function(num) { return num * num }) .value(); => // [2, 200] (alerted) => [4, 40000] What is the method chain in this context? I always thought of method chaining as the concept of chaining methods off of one another: object.foo().bar().baz() . I

Should exceptions be chained in C++? [duplicate]

删除回忆录丶 提交于 2019-11-30 08:56:42
This question already has an answer here: Proper/elegant way of implementing C++ exception chaining? 4 answers How to simulate inner exception in C++ 6 answers I just finished work on a C++-program where I've implemented my own exceptions (although derived from std::exception). The practice I've applied when one exception causes a chain reaction, propagating the error upwards and giving rise to other exceptions, is to concatenate the error message at each appropriate step across the modules (read classes). I.e. the old exception itself is dropped and a new exception is created, but with a

Angular2 - How to chain async service calls (http requests) in a component?

北战南征 提交于 2019-11-30 08:19:20
问题 I have a component which first need to call a service that POST something. Then in the same component I want to wait until the POST is done, to call another service which GETs data. How can I make the GET call wait for the POST call to finish? In new-version.component.ts: private createNewVersion(value) { ... // create new version, then call on all available versions // POST call this._newVersionService.createNewVersion(vnr); // GET call this._versionService.getAvailableVersions(); ... } In

Python: jQuery-like function chaining?

我与影子孤独终老i 提交于 2019-11-30 07:28:09
I couldn't find anything on this subject on Google, so I think I should ask it here: Is it possible to chain functions with Python, like jQuery does? ['my', 'list'].foo1(arg1, arg2).foo2(arg1, arg2).foo3(arg1, arg2) #etc... I am losing a lot of space and readability when I write this code: foo3(foo2(foo1(['my', 'list'], arg1, arg2), arg1, arg2), arg1, arg2) #etc... There seems to exist some illusive library for creating such functions, but I can't seem to see why this has to be so complicated-looking... Thanks! Here's an expansion of Simon's ListMutator suggestion: class ListMutator(object):

Get detail messages of chained exceptions Java

喜你入骨 提交于 2019-11-30 04:58:10
I'd like to know how I could I thorw a "final" Exception , containing a detail message with all the detail messages of a number of chained exceptions. For example suppose a code like this: try { try { try { try { //Some error here } catch (Exception e) { throw new Exception("FIRST EXCEPTION", e); } } catch (Exception e) { throw new Exception("SECOND EXCEPTION", e); } } catch (Exception e) { throw new Exception("THIRD EXCEPTION", e); } } catch (Exception e) { String allMessages = //all the messages throw new Exception(allMessages, e); } I'm not interested in the full stackTrace , but only in

How to Chain Commands at a Special PowerShell 4 Command Prompt?

只愿长相守 提交于 2019-11-29 18:24:02
Normally, PowerShell commands can be chained with semicolons. The following opens 2 notepads: PS> notepad; notepad You can also chain a more complex statement: PS> Add-Type -AssemblyName System.IO.Compression; ` > $src = "C:\aFolder"; $zip="C:\my.zip"; ` > [io.compression.zipfile]::CreateFromDirectory($src, $zip) Chained PowerShell commands can also be called from a CMD command-line: C:\> powershell notepad; notepad This post describes a method to create a .Net 4.0 PowerShell prompt, even if .Net 2.0 is the active framework on your OS. You create a .cmd script, and run that. Now you're in a

Removing Attributes from XSLT and working with result set

妖精的绣舞 提交于 2019-11-29 14:38:51
Is it possible to remove xml attributes from XSLT AND work with the resulting transform? In other words, I have the following XML: <?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet type="text/xsl" href="XML_TEST.xslt"?> <report xmlns="abc123"> <book> <page id="22"> </page> <page id="23"> </page> </book> </report> I know that I can use the following XSLT to strip the attributes: <xsl:template match ="@*" > <xsl:attribute name ="{local-name()}" > <xsl:value-of select ="." /> </xsl:attribute> <xsl:apply-templates/> </xsl:template> <xsl:template match ="*" > <xsl:element name ="{local