async-await

ConfigureAwait(true) not returning on the context it was awaited on

╄→尐↘猪︶ㄣ 提交于 2021-02-02 09:46:45
问题 Sample : static void Main(string[] args) { int counter = 0; var t = new System.Timers.Timer(); t.Interval = 3000; t.Elapsed += async (sender, e) => { Debug.WriteLine("Before await - Thread : {0} , Counter : {1}", Thread.CurrentThread.ManagedThreadId, counter); await Task.Delay(1000).ConfigureAwait(true); Debug.WriteLine("Ater await Thread : {0}, Counter : {1} ", Thread.CurrentThread.ManagedThreadId, counter); counter++; if (counter == 2) { Debug.WriteLine("Stop"); t.Stop(); } }; t.Start();

React hooks state is not updated right after it's set with async

心不动则不痛 提交于 2021-01-29 19:56:44
问题 Is it not possible to get the updated hook value right after setting it? I assume react only updates value for the next render, since my screen following async-await renders fine. Just logs are not printing out the state I was expecting. Not sure if I'm suppose to log state like this, or write another useEffect just for the states I need and put console.log in there instead? const [uid, setUID] = useState<string | undefined>(undefined); const [state, setState] = useState<{ [key: string]: any;

Flutter firestore getting data receiver: null error

半腔热情 提交于 2021-01-29 19:56:30
问题 I searched a lot but couldn't find a solution. I need your help. In my database model, I have a method like this to get the data: Future<Map<String,dynamic>> getSystemSettings() async { var response = await _firestore.collection("system").doc("settings").get(); return response.data(); } Later, I want to use the data in the form of Map <String, dynamic> from the class I want to get the data from by calling the method as follows. getValues() { database.getSystemSettings().then((value) { print(

System.ObjectDisposedException: Cannot access a disposed object, ASP.NET Core 3.1

≡放荡痞女 提交于 2021-01-29 18:09:22
问题 I am writing an API using SignalR in ASP.NET Core 3.1. I am totally new to .NET Core, and am pretty new to SignalR too. I am having an issue executing MongoDB (Atlas) queries which are running in transactions. It appears that the transaction sessions are expiring before the queries are executing. I'm quite sure it's a async / await issue, but don't seem to be able to fix it. My Hub method looks like this: public async Task<bool> UpdateProfile(object profileDto) { try { ProfileDTO profile = (

NodeJS ASync call of MongoClient GetData routine

眉间皱痕 提交于 2021-01-29 17:58:11
问题 The code below is a mix of https://www.w3schools.com/nodejs/nodejs_mongodb_find.asp and https://stackoverflow.com/questions/49982058/how-to-call-an-async-function#:~:text=Putting%20the%20async%20keyword%20before,a%20promise%20to%20be%20resolved. When you look at the console.log below the code, things seem to be running out of order. I thought by making the function async and using the .then I would avoid those issues. I want the MongoDB data retrieval function separate from the app.get

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

How can I use async lambdas without a try/catch block and still have custom error messages?

前提是你 提交于 2021-01-29 15:21:02
问题 I'm trying to avoid wrapping all my awaited calls in an async lambda with a try catch. I want to catch and send custom error responses, but wrapping each awaited call in a try/catch is syntactically ugly compared to .catch() . Is there a way to do something like this: exports.hanlder = async (event, context, callback) => { const foo = await bar(baz).catch((error) => { eventResponse.statusCode = 503; eventResponse.body = JSON.stringify({ message: 'unable to bar' , error}); // normally we'd

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

Async await not work properly inside map function

空扰寡人 提交于 2021-01-29 11:51:20
问题 I have a Dataset Structure like this: _id: SomeMongoID, value: "a", counter: 1 } So initially my database table is empty. Now I have an array where value is like: const array = ["a", "a", "a"] What I want is initially the first time I do the search, so it will empty result so at that case in insert the query, now next time it get the entry so simply increment the counter. For that, I wrote the code: const testFunction = async(array) => { try { await Promise.all( array.map(async x => { const

Handling HeroCards responses In Microsoft Bot Framework v4 for NodeJS

情到浓时终转凉″ 提交于 2021-01-29 07:45:10
问题 I am using NodeJs API of Microsoft Bot Framework v4 . And my dialogs are not hardcoded in the ActivityHandler , I just call from there. I am using Waterfall dialogs. So when I try to show Carousel card on messenger (which is HeroCard on Microsoft bot framework), it shows up successfully but when I click any button on cards, there is no response for next dialog. I tried to handle on onMessage hook but, it just tries to validate the response and throw errors. .... ListItems extends