asynchronous

Getting a result in the future?

痴心易碎 提交于 2021-02-07 05:58:07
问题 I'm looking to get a result from a method which can take a while to complete and doesn't actually return the object, so I'd like to deal with it as effectively as possible. Here's an example of what I'm trying to achieve: public static void main (String[] args) { Object obj = someMethod(); System.out.println("The object is" + obj + ", wooh!"); } public void callObject() { // Sends request for the object } public void receiveObject(Object object) { // Received the object } public Object

Load XDocument asynchronously

佐手、 提交于 2021-02-07 05:51:24
问题 I want to load large XML documents into XDocument objects. The simple synchronous approach using XDocument.Load(path, loadOptions) works great, but blocks for an uncomfortably long time in a GUI context when loading large files (particularly from network storage). I wrote this async version with the intention of improving responsiveness in document loading, particularly when loading files over the network. public static async Task<XDocument> LoadAsync(String path, LoadOptions loadOptions =

SslStream equivalent of TcpClient.Available?

岁酱吖の 提交于 2021-02-07 05:48:05
问题 Based on the advice of @Len-Holgate in this question, I'm asynchronously requesting 0-byte reads, and in the callback, accept bytes the available bytes with synchronous reads, since I know the data is available and won't block. This seems so efficient and wonderful. But then I add the option for SslStream, and the approach falls apart. The zero-byte read is fine, but the SslStream decrypts the bytes, leaving a zero byte-count in the TcpClient's buffer (appropriately so), and I cannot

Exceptions thrown in asynchronous javascript not caught

孤街醉人 提交于 2021-02-07 05:39:21
问题 Basically, why isn't this exception caught? var http = require('http'), options = { host: 'www.crash-boom-bang-please.com', port: 80, method: 'GET' }; try { var req = http.request(options, function(res) { res.setEncoding('utf8'); res.on('data', function (chunk) { console.log('BODY: ' + chunk); }); }); req.on('error', function(e) { throw new Error("Oh noes"); }); req.end(); } catch(_error) { console.log("Caught the error"); } Some people suggest that these errors need to be handled with event

tracking request flow by ID in node.js

心不动则不痛 提交于 2021-02-07 03:55:18
问题 In my node.js application whenever I get request I'd like to "stamp" it with some unique ID and be able to track all the activities (log statements) related to this request by this ID. So when request comes in and I pass its handing to lower application layers (services, database calls etc) I want to be able to collect all logs matching given request ID to rebuild its journey through the app. So having this picture, I use request-local module now, but it does some heavy magic that has just

tracking request flow by ID in node.js

六月ゝ 毕业季﹏ 提交于 2021-02-07 03:54:41
问题 In my node.js application whenever I get request I'd like to "stamp" it with some unique ID and be able to track all the activities (log statements) related to this request by this ID. So when request comes in and I pass its handing to lower application layers (services, database calls etc) I want to be able to collect all logs matching given request ID to rebuild its journey through the app. So having this picture, I use request-local module now, but it does some heavy magic that has just

How to make promise.all wait for nested promise.all?

不打扰是莪最后的温柔 提交于 2021-02-07 03:41:11
问题 So I have a problem with JavaScript Promises. I'm using native implementation for the sake of reducing dependencies. An illustrative example of what I need. I need to retrieve lists of books, book authors and purchases. I also need an author profile for each of the authors. After I got all of that, I need to create a nice set of Authors with their books and purchase list for each of the books. Lists and profiles are separate API JSON calls. The only dependency is that I need a list of authors

How to make promise.all wait for nested promise.all?

痞子三分冷 提交于 2021-02-07 03:40:13
问题 So I have a problem with JavaScript Promises. I'm using native implementation for the sake of reducing dependencies. An illustrative example of what I need. I need to retrieve lists of books, book authors and purchases. I also need an author profile for each of the authors. After I got all of that, I need to create a nice set of Authors with their books and purchase list for each of the books. Lists and profiles are separate API JSON calls. The only dependency is that I need a list of authors

How do you know when an indefinitely long promise chain has completely finished?

╄→尐↘猪︶ㄣ 提交于 2021-02-07 03:28:43
问题 I was trying to use promises to force serialization of a series of Ajax calls. These Ajax calls are made one for each time a user presses a button. I can successfully serialize the operations like this: // sample async function // real-world this is an Ajax call function delay(val) { log("start: ", val); return new Promise(function(resolve) { setTimeout(function() { log("end: ", val); resolve(); }, 500); }); } // initialize p to a resolved promise var p = Promise.resolve(); var v = 1; // each

Angular 6 observables - extract data from .subscribe() function and use it elsewhere

我的未来我决定 提交于 2021-02-07 03:27:51
问题 I'm banging my head against the wall with observables. Almost all of the documentation I can find is in the older rxjs syntax. I have an API call which is an observable. I'm calling it elsewhere and subscribing to it - trying to populate a table with the data from this GET request. If I simply console.log my getData function, it logs the subscription rather than my data. I can successfully console.log data within the .subscribe function, but I want to use data outside of .subscribe() . How do