async

Spring RestTemplate - async vs sync restTemplate

匿名 (未验证) 提交于 2019-12-03 02:59:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I wrote the following code to test the performance of both the sync RestTemplate and AsyncRestTemplate. I just ran it a few times manually on POSTMAN. We are just passing 10 references into a GET call so that we can return 10 links: RestTemplate - synchronous and returns in 2806ms: ArrayList<String> references = new ArrayList<>(); ArrayList<String> links = new ArrayList<>(); RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); for (int i = 0; i < 10; i++) { ResponseEntity

Async video streaming in ASP.Net Core Web Api is not working

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have used http://www.strathweb.com/2013/01/asynchronously-streaming-video-with-asp-net-web-api/ this technique before and worked perfect for async video streaming. But for ASP.NET Core this way is not working as expected. By Video streaming class is: public class VideoStream { private readonly string _filename; public VideoStream(string filename) { _filename = filename; } public async Task WriteToStream(Stream outputStream, HttpContent content, TransportContext context) { try { var buffer = new byte[65536]; using (var video = File.Open(

jsTree: async loading

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to use this jQuery plugin (jsTree) in one of my project. All the others I've found haven't been recently updated. Anyway, I am using this plugin to load a folder structure, but I would like to do this operation async. The examples I've found on their site (called async) are ridiculous. I've tried to check on the Internet but it seems that most people load the whole tree. I would like to load a branch on every single node click. I am using JSON. Thank in advance 回答1: I'm using this with jsTree in jQuery 1.4 at the moment, here's

Asynchronous context manager

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have an asynchronous API which I'm using to connect and send mail to an SMTP server which has some setup and tear down to it. So it fits nicely into using a contextmanager from Python 3's contextlib . Though, I don't know if it's possible write because they both use the generator syntax to write. This might demonstrate the problem (contains a mix of yield-base and async-await syntax to demonstrate the difference between async calls and yields to the context manager). @contextmanager async def smtp_connection(): client = SMTPAsync() ... try

How to support async methods in a TransactionScope with Microsoft.Bcl.Async in .NET 4.0?

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a method similar to: public async Task SaveItemsAsync(IEnumerable<MyItem> items) { using (var ts = new TransactionScope()) { foreach (var item in items) { await _repository.SaveItemAsync(item); } await _repository.DoSomethingElse(); ts.Complete(); } } This of course has issues because TransactionScope doesn't play nice with async/await. It fails with an InvalidOperationException with the message: "A TransactionScope must be disposed on the same thread that it was created." I read about TransactionScopeAsyncFlowOption in this answer ,

async Task&lt;HttpResponseMessage&gt; Get VS HttpResponseMessage Get

匿名 (未验证) 提交于 2019-12-03 02:52:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I would need your help in the following. For nearly a month, I have been reading regarding Tasks and async . I wanted to try to implement my new acquired knowledege, in a simple wep api project. I have the following methods and both of them working as expected: public HttpResponseMessage Get() { var data = _userServices.GetUsers(); return Request.CreateResponse(HttpStatusCode.OK, data); } public async Task<HttpResponseMessage> Get() { var data = _userServices.GetUsers(); return await Task<HttpResponseMessage>.Factory.StartNew(() => { return

PagedList and Async

匿名 (未验证) 提交于 2019-12-03 02:51:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using PagedList in my Views, but my scaffolded Controller is generated with this kind of default Index Action: public async Task<ActionResult> Index() { return View(await db.Claimants.ToListAsync()); } I didn't find an extension for PagedList to work with async . My methods have to be changed to a form like this: public ActionResult Index(int? page) { var claimants = db.Claimants.OrderBy(b => b.Name); var notNullPage = page ?? 1; return View(claimants.ToPagedList(notNullPage, 50)); } Is there a reasonable way to work with PagedList and

Does JSHint support async/await?

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm using JSHint for the JavaScript project (with the Visual Studio Code). And in this project I use async / await, which JSHint highlights as errors. I tried to set up jshint, but the it seems like the maxim version of "esversion" is 6. Does jshint support async/await yet? If it does, how to turn it on? And if not, are there any workarounds? 回答1: The JSHINT developing community considers that: JSHINT should first support all the ES6 syntax before start implementing ES7 features. Async Functions are only at stage 1, so the syntax can change

Angular 2 Multiple validators

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Is it possible to have multiple validators on a form field? I tried this, but it resulted in some strange errors (field was never valid, even if requirements were met) this.username = new Control('', Validators.minLength(5), Validators.required); How can I use multiple validators? 回答1: You can combine validators using Validators.compose() this.username = new Control('', Validators.compose( [Validators.minLength(5), Validators.required])); for async validators use this.username = new Control('', null, Validators.composeAsync(

Swift 3 warning for dispatch async

匿名 (未验证) 提交于 2019-12-03 02:49:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have this code: DispatchQueue.global(priority: DispatchQueue.GlobalQueuePriority.default).async { let url = URL(string: itemImageURL ) let data = try? Data(contentsOf: url!) if data != nil { DispatchQueue.main.async{ cell.advImage!.image = UIImage(data: data!) } } } I get this warning in Swift 3: 'default' was deprecated in iOS 8.0: Use qos attributes instead on the first line. Haven't found yet a solution. Has anybody? 回答1: try qos: DispatchQoS.QoSClass.default instead of priority: DispatchQueue.GlobalQueuePriority.default DispatchQueue