asynchronous

How to find out which of these sites failed

微笑、不失礼 提交于 2021-02-05 05:39:08
问题 I have an asyncronous task that goes out to several websites parses some data and returns the data when its finished. In the event that one or more of the websites fail - I need to find out which ones failed. Is this possible? Here is some example code I have: The controller public async Task<ActionResult> Index() { Models.WebSite ws = new Models.WebSite(); List<Task<string>> webList = new List<Task<string>>(); webList.Add(ws.GetWebsiteInfoAsync("http://website1.com")); webList.Add(ws

does last async call in async method require await?

天涯浪子 提交于 2021-02-05 05:19:09
问题 I can't understand if await statement is required when async method call is the last call in my async method. E.g. public async Task CallAsync(byte[] data) { await Call1Async(data); Call2Async(data); } public async Task Call1Async(byte[] data) { ... } public async Task Call2Async(byte[] data) { ... } The above would compile but with a warning "consider applying await to this method". But I think it would be waste of resources to apply await for the last call in the method. At the same time,

does last async call in async method require await?

余生颓废 提交于 2021-02-05 05:18:26
问题 I can't understand if await statement is required when async method call is the last call in my async method. E.g. public async Task CallAsync(byte[] data) { await Call1Async(data); Call2Async(data); } public async Task Call1Async(byte[] data) { ... } public async Task Call2Async(byte[] data) { ... } The above would compile but with a warning "consider applying await to this method". But I think it would be waste of resources to apply await for the last call in the method. At the same time,

Cancellation Token source example

瘦欲@ 提交于 2021-02-05 05:11:54
问题 I'm doing some asynchronous operations and I would like to use CancellationToken to stop an async task from running if the user for example requests this. In order to do so is it a good practice to have a Dictionary with which I can find the correct Thread in order to stop the correct operation? What I'm currently looking at is the following : public Dictionary<Thread, CancellationToken> CancellationTokenData; Thus, if the user requests a cancellation on an operation it should behave

Intercept XMLHttpRequest and send a Promise

谁说胖子不能爱 提交于 2021-02-04 21:48:40
问题 I am building a proxy for a video player which can intercept the http requests and send back the response using a Promise which can be resolved asynchronously I have found this way of intercepting a http request // save original `send` method const origSend = XMLHttpRequest.prototype.send; // redefine `send` method // you could also pass extra parameters if needed XMLHttpRequest.prototype.send = (...origParams) => { console.log('send called'); origSend(...origParams); } Now I don't want to

Intercept XMLHttpRequest and send a Promise

五迷三道 提交于 2021-02-04 21:44:47
问题 I am building a proxy for a video player which can intercept the http requests and send back the response using a Promise which can be resolved asynchronously I have found this way of intercepting a http request // save original `send` method const origSend = XMLHttpRequest.prototype.send; // redefine `send` method // you could also pass extra parameters if needed XMLHttpRequest.prototype.send = (...origParams) => { console.log('send called'); origSend(...origParams); } Now I don't want to

Promise - `then()` not works as expect

一世执手 提交于 2021-02-04 19:43:06
问题 I do have 2 function. I am chaining with then() method for promise . But I am trying to initiate the second function after the first promise happend. But now the second function call as first. how to fix this? or any issue with my code? here is my try: var getData = function(){ return new Promise((resolve, reject) => { setTimeout(() => { resolve(42); //consoles as second }, 5000); }) } var getDataMoreData = function(){ return new Promise((resolve, reject) => { setTimeout(() => { resolve(43);

Behavior of async await with new threads

孤街醉人 提交于 2021-02-04 19:31:38
问题 I am trying to understand the precise behavior of async/await and am having a small amount of trouble wrapping my head around it. Consider this example: public async void StartThread() { while(true){ SomeOtherClass.SomeSynchronousStuff(); var something = await SomeOtherClass.SomeOtherAsyncMethod(); } } public void ConstructorForThisClass() { Thread thread = new Thread(StartThread); thread.Start(); } My understanding of async/await is that what is happening under the covers is that the

why does a function with setTimeout not lead to a stack overflow

人盡茶涼 提交于 2021-02-04 16:45:38
问题 I was writing a test for handling huge amounts of data. To my surprise, if I added a setTimeout to my function, it would no longer lead to a stack overflow (how appropriate for this site). How is this possible, the code seems to be really recursive. Is every setTimeout call creating it's own stack? Is there way to achieve this behavior (handle a huge array/number asynchronous and in order) without increasing the needed memory? function loop( left: number, callbackFunction: (callback: () =>

Communicate from server to client side in Google Apps script

不想你离开。 提交于 2021-02-04 13:50:48
问题 I am trying to write a Google Apps script which has a client and server side component. The client side component displays a progress bar. The client calls server side functions (which are called asynchronously), whose progress has to be shown in the client side progress-bar. Now, what I want is to be able to update the client side progress bar based on feedback from the server side functions. Is this possible? The complexity is created due the the fact that JS makes the server-side calls