async-await

IMobileServiceClient.PullAsync deadlock when trying to sync with Azure Mobile Services

无人久伴 提交于 2019-12-31 04:02:47
问题 I have the classes below. public class AzureMobileDataContext : IAsyncInitialization { private static readonly Lazy<AzureMobileDataContext> lazy = new Lazy<AzureMobileDataContext> (() => new AzureMobileDataContext( new MobileServiceClient( "http://myservice.azure-mobile.net/", "123456789ABCDEFGHIJKLMNOP"))); public static AzureMobileDataContext Instance { get { return lazy.Value; } } public Task Initialization { get; private set; } public IMobileServiceClient Context { get; private set; }

Is setTimeout required?

北城余情 提交于 2019-12-31 03:14:28
问题 I have a question to async, await and setTimeout(). I thought, I use asynchron functions for slow processes. So I tried it with a large loop. On my Computer, it needs few seconds to run the following code: function slowFunction() { return new Promise(resolve => { setTimeout(() => { for (let i = 0; i < 4000000000; i++) {}; resolve('Ready at ' + new Date().toLocaleTimeString('de')); }, 0); }); }; console.log('Start: ' + new Date().toLocaleTimeString('de')); (async () => { console.log('Call slow

ES7 async await functions with babel-loader not working

泪湿孤枕 提交于 2019-12-31 01:11:12
问题 I'm trying to run async await functions in JavaScript using the babel-loader of webpack. I'm using the following configuration: { name: 'client', context: path.join(__dirname, 'src', 'static', 'scripts'), entry: { index: './index.js' }, output: { path: path.join(__dirname, 'src', 'static', 'bundles'), filename: '[name].js' }, module: { loaders: [ { test: /\.js$/, loader: 'babel', query: { presets: ['es2015', 'stage-0'] } } ] }, resolve: { root: path.join(__dirname), fallback: path.join(_

Using async requires async function, but my function is async

耗尽温柔 提交于 2019-12-30 22:26:16
问题 I'm adapting a library that uses callback to use Promises. It's working when I use then() , but it doesn't work when I use await . > dbc.solve [AsyncFunction] > await dbc.solve(img) await dbc.solve(img) ^^^^^ SyntaxError: await is only valid in async function The code for dbc.solve is: module.exports = DeathByCaptcha = (function() { function DeathByCaptcha(username, password, endpoint) { ... } DeathByCaptcha.prototype.solve = async function(img) { return new Promise( function(resolve, reject)

should we choose async await over Promise in Javascript

狂风中的少年 提交于 2019-12-30 17:23:19
问题 I know that the async await is the new Promise in the town and it is a new way to write asynchronous code and I also know that We didn’t have to write .then , create an anonymous function to handle the response Async/await makes it finally possible to handle both synchronous and asynchronous errors with the same construct, good old try/catch The error stack returned from a promise chain gives no clue of where the error happened. However, the error stack from async/await points to the function

Projection using async delegate/lambda

十年热恋 提交于 2019-12-30 13:11:45
问题 The following code will not compile against the Async CTP in Visual Studio 2010: Enumerable.Range(1, 5).Select(async x => { await TaskEx.Delay(100); return 5; }); The compilation error is as follows: Test.cs(40,13): error CS1928: 'System.Collections.Generic.IEnumerable<int>' does not contain a definition for 'Select' and the best extension method overload 'System.Linq.Enumerable.Select<TSource,TResult>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,TResult>)' has some

Projection using async delegate/lambda

限于喜欢 提交于 2019-12-30 13:11:44
问题 The following code will not compile against the Async CTP in Visual Studio 2010: Enumerable.Range(1, 5).Select(async x => { await TaskEx.Delay(100); return 5; }); The compilation error is as follows: Test.cs(40,13): error CS1928: 'System.Collections.Generic.IEnumerable<int>' does not contain a definition for 'Select' and the best extension method overload 'System.Linq.Enumerable.Select<TSource,TResult>(System.Collections.Generic.IEnumerable<TSource>, System.Func<TSource,TResult>)' has some

How to use async/await with a library that uses an event-based asynchronous pattern?

≯℡__Kan透↙ 提交于 2019-12-30 10:32:34
问题 I use a library that has an asynchronous method called DoWork(...) that will raise a WorkDone event when the operation completes. I would like to write a method that calls this library, but instead of maintaining the same pattern I would like my method to be async so it can be called with await . In essence, what I am trying to do is: public async Task<Result> SomeMethod() { var result = new Task<Result>(); library.WorkDone += (data) => { result.Result = data; } library.DoWork(); return await

Should I always use Task.Delay instead of Thread.Sleep? [duplicate]

筅森魡賤 提交于 2019-12-30 10:05:04
问题 This question already has answers here : When to use Task.Delay, when to use Thread.Sleep? (4 answers) Closed 4 years ago . I have recently seen several recommendations stating that Thread.Sleep should never be used in production code (most recently in this SO question). Many of these advocate for using Task.Delay instead. Most of the explanations I've found use UI applications as examples, since the advantages to Task.Delay are obvious (not blocking the UI). In my case, I am using Thread

StackExchange.Redis Deadlocking

心已入冬 提交于 2019-12-30 08:34:13
问题 I'm using StackExchange.Redis (SE.R henceforth) in my Nancy application. There is a single global ConnectionMultiplexer that gets automatically passed around by Nancy's TinyIoC via constructor parameters, and any time I try and use GetDatabase and one of the *Async methods (sync methods only start failing after one of the async methods have been attempted) my application deadlocks. Looking at my parallel stacks it appears that I have four threads: The thread that called Result on one of my