async

Redux: Using async middlewares vs dispatching actions on success functions

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to integrate Redux into my React project. Currently I'm not using any Flux framework. My app gets some data from the API and displays it in a pretty way, like so: componentDidMount () { getData (); } getData () { const self = this ; ajax ({ url : apiUrl , }) . success ( function ( data ) { self . setState ({ data : data , }); }) . error ( function () { throw new Error ( 'Server response failed.' ); }); } In reading about Redux, I've settled on two possible approaches that I could use for handling storing my success data

Async-await - Am I over doing it?

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Recently I've developed doubts about the way I'm implementing the async-await pattern in my Web API projects. I've read that async-await should be "all the way" and that's what I've done. But it's all starting to seem redundant and I'm not sure that I'm doing this correctly. I've a got a controller that calls a repository and it calls a data access (entity framework 6) class - "async all the way". I've read a lot of conflicting stuff on this and would like to get it cleared-up. EDIT: The referenced possible duplicate is a good post, but not

async/await with ConfigureAwait's continueOnCapturedContext parameter and SynchronizationContext for asynchronous continuations

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I would like put the code first and then explain the situation and ask my question based on that: public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private async void Button_Click_2(object sender, RoutedEventArgs e) { var result = await GetValuesAsync(); Foo.Text += result; } public async Task GetValuesAsync() { using (var httpClient = new HttpClient()) { var response = await httpClient .GetAsync("http://www.google.com") .ConfigureAwait(continueOnCapturedContext: false); // This is the continuation for

ts An async function or method in ES5/ES3 requires the 'Promise' constructor

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Hello I'm Using async/await in my TypeScript Project, But I Get this log: [ts] An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your --lib option. How Can I Solve That? 回答1: As the error message says, add lib: es2015 to your tsconfig.json // tsconfig.json { "compilerOptions" : { "lib" : [ "es2015" ] } } 回答2: Try this package which contains type definitions for es6-promise npm install --save @types/es6-promise 回答3: If you

ts An async function or method in ES5/ES3 requires the 'Promise' constructor

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Hello I'm Using async/await in my TypeScript Project, But I Get this log: [ts] An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your --lib option. How Can I Solve That? 回答1: As the error message says, add lib: es2015 to your tsconfig.json // tsconfig.json { "compilerOptions": { "lib": [ "es2015" ] } } 回答2: Try this package which contains type definitions for es6-promise npm install --save @types/es6-promise 回答3: If you are on VS,

ts An async function or method in ES5/ES3 requires the 'Promise' constructor

匿名 (未验证) 提交于 2019-12-03 01:47:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Hello I'm Using async/await in my TypeScript Project, But I Get this log: [ts] An async function or method in ES5/ES3 requires the 'Promise' constructor. Make sure you have a declaration for the 'Promise' constructor or include 'ES2015' in your --lib option. How Can I Solve That? 回答1: As the error message says, add lib: es2015 to your tsconfig.json // tsconfig.json { "compilerOptions": { "lib": [ "es2015" ] } } 回答2: Try this package which contains type definitions for es6-promise npm install --save @types/es6-promise 回答3: If you are on VS,

When to use and when not to use Python 3.5 `await` ?

匿名 (未验证) 提交于 2019-12-03 01:45:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm getting the flow of using asyncio in Python 3.5 but I haven't seen a description of what things I should be await ing and things I should not be or where it would be neglible. Do I just have to use my best judgement in terms of "this is an IO operation and thus should be await ed"? 回答1: By default all your code is synchronous. You can make it asynchronous defining functions with async def and calling this functions with await . More correct question is "When should I write asynchronous code instead of synchronous?". Answer is "When you

Is it possible to chain async calls using Guava?

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to chain async rest service calls and have single callback when they finished. Is it possible to do it with guava? 回答1: You can use Futures.chain for chaining ListenableFuture s: final ListeningExecutorService service1 = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(16)); final ListeningExecutorService service2 = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(16)); ListenableFuture service1result = service1.submit(new Callable () { @Override public String call() throws Exception { return "service1result"

JavaScript async await doesn't work inside forEach loop

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have few queries to a database which I want to gather into a transaction. let t = await db.sequelize.transaction() try { let adr = await addressRepo.add(address, t) let user = await userRepo.add(email, password, name, surname, phone, NIP, REGON, id_number, adr.id, t) await userRoleRepo.add(user.id, user_role, t) if (languages != null) { languages.forEach(async function (language) { await userLanguageRepo.add(user.id, language.id, language.main, t) }) } await t.commit() res.status(201).json(user) } catch (error) { await t.rollback() }

How to use SOCKS proxies to make requests with aiohttp?

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to use aiohttp to make asynchronous HTTP requests over multiple SOCKS proxies. Basically, I am creating a pool of Tor clients with different IP addresses, and want to be able to route HTTP requests through them using aiohttp . Based on the suggestions here and here , I have been trying to use aiosocks , but the examples in those threads do not work (if they ever did) because they are based on an old version of aiosocks with a different API. Documentation and examples of using aiosocks online are very sparse (it doesn't seem