deferred-execution

twisted: difference between `defer.execute` and `threads.deferToThread`

一笑奈何 提交于 2019-12-09 16:31:53
问题 What is the difference between defer.execute() and threads.deferToThread() in twisted? Both take the same arguments - a function, and parameters to call it with - and return a deferred which will be fired with the result of calling the function. The threads version explicitly states that it will be run in a thread. However, if the defer version doesn't, then what would ever be the point of calling it? Code that runs in the reactor should never block, so any function it calls would have to not

Is it possible to determine if an IEnumerable<T> has deffered execution pending?

喜你入骨 提交于 2019-12-08 16:41:09
问题 I have a function that accepts an Enumerable. I need to ensure that the enumerator is evaluated, but I'd rather not create a copy of it (e.g. via ToList() or ToArray()) if it is all ready in a List or some other "frozen" collection. By Frozen I mean collections where the set of items is already established e.g. List, Array, FsharpSet, Collection etc, as opposed to linq stuff like Select() and where(). Is it possible to create a function "ForceEvaluation" that can determine if the enumerable

How to maintain LINQ deferred execution?

你。 提交于 2019-12-05 03:30:33
Suppose I have an IQueryable<T> expression that I'd like to encapsulate the definition of, store it and reuse it or embed it in a larger query later. For example: IQueryable<Foo> myQuery = from foo in blah.Foos where foo.Bar == bar select foo; Now I believe that I can just keep that myQuery object around and use it like I described. But some things I'm not sure about: How best to parameterize it? Initially I've defined this in a method and then returned the IQueryable<T> as the result of the method. This way I can define blah and bar as method arguments and I guess it just creates a new

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

a 夏天 提交于 2019-12-04 23:46:38
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 much more complex than this simple illustration, what is a good rule of thumb to use for deciding if

Why does `defer recover()` not catch panics?

左心房为你撑大大i 提交于 2019-12-04 16:43:22
问题 Why does a call to defer func() { recover() }() successfully recover a panicking goroutine, but a call to defer recover() not? As an minimalistic example, this code doesn't panic package main func main() { defer func() { recover() }() panic("panic") } However, replacing the anonymous function with recover directly panics package main func main() { defer recover() panic("panic") } 回答1: The Handling panic section mentions that Two built-in functions, panic and recover , assist in reporting and

When using yield within a “using” statement, when does Dispose occur?

随声附和 提交于 2019-12-04 10:01:30
问题 I have a question regarding deferred execution and the disposing of data. Consider the following example: private IEnumerable<string> ParseFile(string fileName) { using(StreamReader sr = new StreamReader(fileName)) { string line; while((line = sr.ReadLine()) != null) { yield return line; } } } private void LineReader(string fileName) { int counter = 0; foreach(string line in ParseFile(fileName)) { if(counter == 2) { break; // will this cause a dispose on the StreamReader? } else { Console

Using LINQ .Select() to cast into new type is TOO slow?

做~自己de王妃 提交于 2019-12-04 05:30:57
问题 Current project, broke head over this problem: Client Repository: public class ClientRepository { // Members private masterDataContext _db; // Constructor public ClientRepository() { _db = new masterDataContext(); } public IEnumerable<ClientName> GetCorporateClientNames() { return _db.corporate_client_tbs.Select(o => new ClientName { id = o.id, name = o.company_name }).AsEnumerable(); } public IEnumerable<ClientName> GetRetailClientNames() { return _db.retail_client_tbs.Select(o => new

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

我的梦境 提交于 2019-12-03 12:28:06
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 week but maybe I never caught this issue. Console Loading Inline Script VM1400:3 Uncaught TypeError:

Why does `defer recover()` not catch panics?

老子叫甜甜 提交于 2019-12-03 11:44:48
Why does a call to defer func() { recover() }() successfully recover a panicking goroutine, but a call to defer recover() not? As an minimalistic example, this code doesn't panic package main func main() { defer func() { recover() }() panic("panic") } However, replacing the anonymous function with recover directly panics package main func main() { defer recover() panic("panic") } The Handling panic section mentions that Two built-in functions, panic and recover , assist in reporting and handling run-time panics The recover function allows a program to manage behavior of a panicking goroutine.

When using yield within a “using” statement, when does Dispose occur?

青春壹個敷衍的年華 提交于 2019-12-03 05:42:02
I have a question regarding deferred execution and the disposing of data. Consider the following example: private IEnumerable<string> ParseFile(string fileName) { using(StreamReader sr = new StreamReader(fileName)) { string line; while((line = sr.ReadLine()) != null) { yield return line; } } } private void LineReader(string fileName) { int counter = 0; foreach(string line in ParseFile(fileName)) { if(counter == 2) { break; // will this cause a dispose on the StreamReader? } else { Console.WriteLine(line); counter++; } } } Will the break statement immediately cause the reader in ParseFile to