asynchronous

Asynchronous operations within a loop - how to keep control of execution?

一曲冷凌霜 提交于 2021-01-29 19:05:26
问题 Follow-on question to this one. I am trying to generate and save a series of images. Rendering is done by Helix Toolkit, which I am told utilises the WPF composite render thread. This is causing problems because it executes asynchronously. My original problem was that I couldn't save a given image because it hadn't yet been rendered at that time I was trying to save it. The above answer provides a workaround to this by putting the 'save' operation inside an Action which is called with low

Flutter readAsBytesSync file read incomplete to encode base64

白昼怎懂夜的黑 提交于 2021-01-29 18:20:02
问题 List item I'm trying to send a JPG image (captured by ImagePicker in emulator) via HTTP POST with base64 encoding to an AWS REST API. But readAsBytesSync() operation only reads a (head) part of the image (I've tested it printing to the string as bytes) thus base64 can only encode that small part. What may be the reason, many thanks for your help in advance. Future<void> captureImage(ImageSource imageSource) async { try { ImagePicker picker = ImagePicker(); final pickedFile = await picker

Wait for State to update using UseState hook and then run code inside a funciton

空扰寡人 提交于 2021-01-29 18:17:31
问题 const startLive = () => { // connect to websocket only on start button setliveChartState({ ...liveChartState, liveActive: !liveChartState.liveActive, historicLiveActive: true, start: new Date(), }); /*- - - -after updation - - - >*/ const { ws, liveActive } = liveChartState; // if clicked on stop then close websocket if (!liveActive && ws) { ws.close(); clearLiveInterval(); } // if clicked on start and websocket close then connect if ((!ws || ws.readyState === WebSocket.CLOSED)&& liveActive)

Swift write an async/await method with return value

╄→гoц情女王★ 提交于 2021-01-29 17:52:58
问题 I want to write an async-await method with a return value, but my code doesn't work. I also tried another way such as DispatchQueue.global DispatchGroup() and so on. Here is my code: func checkPassCode() -> Bool { var result = false let closure = { (_ flag:Bool) -> Void in result = flag } if var pin = self.keychain.get("pin") { let userPin = self.pin.joined(separator: "") let encryptedData = NSData(base64Encoded: pin, options: []) AsymmetricCryptoManager.sharedInstance

RXJS: returning nested observables

旧城冷巷雨未停 提交于 2021-01-29 16:50:00
问题 I'm trying to return a UserDetail object which consists of a User and Results, User is retrieved via the accessToken of Account (all retrieved via individual async calls). At the moment I'm stuck at figuring out how I can return this UserDetail object when I navigate to the detailcomponent (I know it is not possible to literally return the object since the call is async, but I need to use this object in my component). The code below gives me the following error: Type 'Observable' is not

How to synchronize an async map function in javascript

…衆ロ難τιáo~ 提交于 2021-01-29 14:53:24
问题 I have a async map function but want it to execute synchronously because I need the output of the first statement to be used within the same loop. But the map runs asynchronously even with await statements, can you please help understand why this happens. My use case if to insert a record into mongodb if not present and update it if present in a loop. The data exists in the db but find fails within the loop but works outside. My code: const doSomethingAsync = () => { return new Promise

Wait for it to resolve promise and then insert neatly

末鹿安然 提交于 2021-01-29 14:51:12
问题 I've been watching all morning because this code doesn't work for me. I want once the promise is resolved, the "then" get its last inserted ID (the promise) and neatly insert into the other table. Currently first paints all the promise and then just then or disorderly ... con.query("SELECT ID FROM wp_posts ORDER BY ID DESC LIMIT 0,1;", function(err, result, fields) { console.log(result); for (var i = 0; i < getData.length; i++) { var source = getData[i]["source"]; var text = getData[i]["text"

write string to textblock on different page in C#, UWP

送分小仙女□ 提交于 2021-01-29 13:30:17
问题 How can I write into a TextBlock on a different page? So far it only works with TextBlocks on the same page. The async function is in Page_1 . The TextBlock is on Page_2 . public async void Serial() { string rxBuffer; //code //code //code while (true) { textblock_DebugRx_Gas_live.Text = rxBuffer; } } 回答1: write string to textblock on different page in C#, UWP If the two page display in foreground at same time like following. <Grid> <Grid.RowDefinitions> <RowDefinition Height="1*"/>

axios.get function in ComponentDidMount not setting state as expected

时光毁灭记忆、已成空白 提交于 2021-01-29 13:29:43
问题 In my header component, I have conditional rendering set to display different links depending on if the user is logged in or not. The conditional rendering works fine EXCEPT the fact that it blinks one set of links before displaying the proper set of links. It dawned on me this is because of the axios.get call I have that retrieves the user's status. The state variable is initially set to false. If the user is logged in, the get call will indicate that and the state variable will get set to

Why am I receiving data when my Socket has disconnected? [duplicate]

左心房为你撑大大i 提交于 2021-01-29 11:58:27
问题 This question already has an answer here : TCP Socket is not stopping receiving data in C# program (1 answer) Closed 21 days ago . I'm having an issue with my Sockets. Basically I have a few listeners that listen on all the available ports on my pc. When a socket connects to one of the listeners, I open a new Socket-connection to handle that connection and my listener goes back to listening. However when a client disconnects I keep on receiving empty data. As you can see in the code below, I