deferred-execution

gometalinter / errcheck returns a warning on deferring a func which returns a variable

♀尐吖头ヾ 提交于 2020-04-07 02:57:07
问题 gometalinter and errcheck return me a warning about deferring a function which returns a variable. Example in a web request: defer r.Body.Close() In this case, Close returns an error variable and it's not checked. Is the best method / idiomatic to defer it inside another function? defer func() { err := r.Body.Close() if err != nil { // fmt, panic or whatever } }() 回答1: If a deferred function has any return values, they are discarded when the function completes (for more details check Spec:

Understanding lazy loading optimization in C#

寵の児 提交于 2020-01-13 19:15:50
问题 After reading a bit of how yield, foreach, linq deferred execution and iterators work in C#. I decided to give it a try optimizing an attribute based validation mechanic inside a small project. The result: private IEnumerable<string> GetPropertyErrors(PropertyInfo property) { // where Entity is the current object instance string propertyValue = property.GetValue(Entity)?.ToString(); foreach (var attribute in property.GetCustomAttributes().OfType<ValidationAttribute>()) { if (!attribute

Child sProc cannot reference a Local temp table created in parent sProc

ぃ、小莉子 提交于 2020-01-06 02:04:06
问题 On our production SQL2000 instance, we have a database with hundreds of stored procedures, many of which use a technique of creating a #TEMP table "early" on in the code and then various inner stored procedures get EXECUTEd by this parent sProc. In SQL2000, the inner or "child" sProc have no problem INSERTing into #TEMP or SELECTing data from #TEMP. In short, I assume they can all refer to this #TEMP because they use the same connection. In testing with SQL2008, I find 2 manifestations of

jQuery - Deferreds waiting for an array of ajax requests to complete even failures

心已入冬 提交于 2020-01-03 15:58:03
问题 How can execute a function after a number of ajax requests have all completed regardless of whether they succeeded or error-ed out? I've been trying to use $.when.apply(this, array) to pass an array of deferred jqXHR objects. However just like the docs say In the multiple-Deferreds case where one of the Deferreds is rejected, jQuery.when immediately >fires the failCallbacks for its master Deferred. Note that some of the Deferreds may still be >unresolved at that point. How can leverage jQuery

jQuery - Deferreds waiting for an array of ajax requests to complete even failures

回眸只為那壹抹淺笑 提交于 2020-01-03 15:56:09
问题 How can execute a function after a number of ajax requests have all completed regardless of whether they succeeded or error-ed out? I've been trying to use $.when.apply(this, array) to pass an array of deferred jqXHR objects. However just like the docs say In the multiple-Deferreds case where one of the Deferreds is rejected, jQuery.when immediately >fires the failCallbacks for its master Deferred. Note that some of the Deferreds may still be >unresolved at that point. How can leverage jQuery

Linq, XmlNodes, foreach's and exceptions

喜夏-厌秋 提交于 2020-01-02 02:02:39
问题 Consider the following code: using System; using System.Collections.Generic; using System.Linq; using System.Xml; using System.Xml.Linq; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(@"<Parts> <Part name=""DisappearsOk"" disabled=""true""></Part> <Part name=""KeepMe"" disabled=""false""></Part> <Part name=""KeepMe2"" ></Part> <Part name=""ShouldBeGone"" disabled=""true""></Part> </Parts>"); XmlNode root

Linq - What is the quickest way to find out deferred execution or not?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-27 22:06:35
问题 What is the quickest way to find out which .net framework linq methods (e.g .IEnumerable linq methods) are implemented using deferred execution vs. which are not implemented using deferred execution. While coding many times, I wonder if this one will be executed right way. The only way to find out is go to MSDN documentation to make sure. Would there be any quicker way, any directory, any list somewhere on the web, any cheat sheet, any other trick up your sleeve that you can share? If yes,

When to use LINQ's .ToList() or .ToArray()

别说谁变了你拦得住时间么 提交于 2019-12-22 02:32:14
问题 After running this code: var input = new List<T>( ... ); var result = input.Select( t => new U(t) ); U first1 = null; foreach ( U u1 in result ) if ( first1 == null ) first1 = u1; U first2 = null; foreach ( U u2 in result ) if ( first2 == null ) first2 = u2; Then 'first1 == first2' evaluates to false even though both U's wrap the same T. I haven't tested it yet, but I think it can be made to evaluate to true by chaining a .ToList() or .ToArray() onto the Select() call. In real code, which is

Script File Executing After Inline Script With CDN or External Domain On HTML injection

£可爱£侵袭症+ 提交于 2019-12-21 04:11:40
问题 I am having an issue with HTML injection into an already loaded DOM where the inline javascript is being loaded after the script file is downloaded. From what I know this should not be async and the inline script should execute after the script file. This works if the domain name is the same as the calling page, but using a CDN or even a subdomain does the same thing. Is there something I should do to rework how I am calling these? I swear this worked before as I had the CDN on for over a

Add defer attribute to javascript_include_tag Rails

喜夏-厌秋 提交于 2019-12-20 11:03:46
问题 Is there some way to add the defer attribute easily using the javascript_include_tag helper in Rails? I.e., is there some easy way to turn <%= javascript_include_tag "blah.js" %> into <script defer src="blah.js"></script> 回答1: <%= javascript_include_tag "blah.js", :defer => "defer" %> This will get you (in development): <script defer="defer" src="/assets/blah.js" type="text/javascript"></script> 回答2: You can also do <%= javascript_include_tag "blah.js", defer: true %> which is more consistent