asynchronous

How to test async function with Sinon JS?

℡╲_俬逩灬. 提交于 2021-02-11 17:06:19
问题 Below is a minimal example of what I want to achieve: I want to test fn3() being called if the async function fn2() resolved (when calling fn1 ). But I somehow failed to do that with sinon 's stub syntax. I would like to know what I misunderstood. // System Under Test export function fn1() { fn2().then(() => { fn3(); }); } export async function fn2() { return new Promise((resolve, reject) => { // expensive work resolve(); }); } export function fn3() { console.log("fn3"); } // Test import * as

How to test async function with Sinon JS?

旧街凉风 提交于 2021-02-11 17:05:31
问题 Below is a minimal example of what I want to achieve: I want to test fn3() being called if the async function fn2() resolved (when calling fn1 ). But I somehow failed to do that with sinon 's stub syntax. I would like to know what I misunderstood. // System Under Test export function fn1() { fn2().then(() => { fn3(); }); } export async function fn2() { return new Promise((resolve, reject) => { // expensive work resolve(); }); } export function fn3() { console.log("fn3"); } // Test import * as

Async operation in Actionscript

删除回忆录丶 提交于 2021-02-11 16:40:19
问题 I've read some things about async waits in Actionscript but can't really do it in practice. Here's a short, simplified version of my code I have in a class: private function getXML():void { var xmlLoader:URLLoader = new URLLoader(); xmlLoader.addEventListener(Event.COMPLETE, loadXML); xmlLoader.load(new URLRequest("test.xml")); } private function loadXML(evt:Event):void { var xmlData:XML = new XML(evt.target.data); this.parseResults(xmlData); } private function parseResults(resultsInput:XML)

Returning data from async call in Swift function

笑着哭i 提交于 2021-02-11 15:20:48
问题 I have created a utility class in my Swift project that handles all the REST requests and responses. I have built a simple REST API so I can test my code. I have created a class method that needs to return an NSArray but because the API call is async I need to return from the method inside the async call. The problem is the async returns void. If I were doing this in Node I would use JS promises but I can't figure out a solution that works in Swift. import Foundation class Bookshop { class

Spring REST endpoint returning StreamingResponseBody: AsyncRequestTimeoutException after 30 seconds

烈酒焚心 提交于 2021-02-11 15:14:32
问题 I have the same problem as described here and here. I tried the answers given and combinations thereof but none solved my issue. When I tried this answer, after 30 seconds, instead of the timeout, the download restarted from the beginning and then, after 30 more seconds, then it timed out. I'm testing by visiting the REST endpoint in Google Chrome and trying to download a file from there. Here I have the project that displays this error. Thanks in advance. Edit: here's the source: src\main

Error: await is only valid in async function when function is already within an async function

回眸只為那壹抹淺笑 提交于 2021-02-11 14:53:16
问题 Goal: Get a list of files from my directory; get the SHA256 for each of those files Error: await is only valid in async function I'm not sure why that is the case since my function is already wrapped inside an async function.. any help is appreciated! const hasha = require('hasha'); const getFiles = () => { fs.readdir('PATH_TO_FILE', (err, files) => { files.forEach(i => { return i; }); }); } (async () => { const getAllFiles = getFiles() getAllFiles.forEach( i => { const hash = await hasha

JavaScript: Does an async function create a new thread?

ぃ、小莉子 提交于 2021-02-11 13:52:48
问题 Mozilla’s documentation on XMLHttpRequest includes the following on the async parameter: Note: Synchronous requests on the main thread can be easily disruptive to the user experience and should be avoided; in fact, many browsers have deprecated synchronous XHR support on the main thread entirely. That makes sense, as you don’t what to hold up the main thread waiting for an indeterminate period of time. If I create an async function which includes usng XMLHttpRequest , would that qualify as a

JavaScript Asynchronicity and Runtime

橙三吉。 提交于 2021-02-11 12:58:53
问题 I have been reading a lot about asynchronous JavaScript, but I still can't really wrap my head around it. From what I understand, asynchronous JavaScript is just writing a handler(s) for asynchronous operation. The asynchronous operation (which is not part of JS Engine) then does all the magic of running the operation on a separate thread, moving callback into message (callback) queue and finally pushing the callback to call stack where it is executed by JS Engine. Should I understand more

JavaScript Asynchronicity and Runtime

我只是一个虾纸丫 提交于 2021-02-11 12:57:04
问题 I have been reading a lot about asynchronous JavaScript, but I still can't really wrap my head around it. From what I understand, asynchronous JavaScript is just writing a handler(s) for asynchronous operation. The asynchronous operation (which is not part of JS Engine) then does all the magic of running the operation on a separate thread, moving callback into message (callback) queue and finally pushing the callback to call stack where it is executed by JS Engine. Should I understand more

What's the best way to create a new UI thread and call back methods on the original thread?

你。 提交于 2021-02-11 12:49:35
问题 I'm writing a plug-in class for a third-party GUI application. The application calls the Run method of my class, passing me a vendor-defined Context object. Any methods or properties in this Context object must be called from the current thread (that is, the application's UI thread). My plug-in code creates a WPF Window and shows it to the user. Some interactions need to call the Context object's methods, but some take time to run. This, of course, freezes my UI. Normally, I would call slow