async-await

HttpClient - PostAsync doesn’t return

三世轮回 提交于 2020-07-08 00:35:35
问题 Does anyone know why HttpClient - PostAsync doesn’t return. It just does nothing. I have had it working occasionally especially for one off posts but it seems sometimes to not do anything especially under load and it doesn't throw an exception which of course makes my code unreliable and hard to debug. I have tried adding ConfigureAwait(false) It makes not difference. I suspect the Task is failing to 'pack' This is in a core 3.0 console app run on macOS Catalina using visual studio code This

Async thread body loop, It just works, but how?

*爱你&永不变心* 提交于 2020-07-06 09:18:15
问题 I have just tested something that I was sure would fail miserably, but to my surprise, it worked flawlessly, and proves to myself that I am still quite mystified by how async-await works. I created a thread, passing an async void delegate as the thread's body. Here's an oversimplification of my code: var thread = new Thread( async () => { while( true ) { await SomeLengthyTask(); ... } }); thread.Start(); thread.Join(); The thing is that as far as I understand, when the execution hits the

Asynchronous SHA256 Hashing

丶灬走出姿态 提交于 2020-07-06 08:59:46
问题 I have the following method: public static string Sha256Hash(string input) { if(String.IsNullOrEmpty(input)) return String.Empty; using(HashAlgorithm algorithm = new SHA256CryptoServiceProvider()) { byte[] inputBytes = Encoding.UTF8.GetBytes(input); byte[] hashBytes = algorithm.ComputeHash(inputBytes); return BitConverter.ToString(hashBytes).Replace("-", String.Empty); } } Is there a way to make it asynchronous? I was hoping to use the async and await keywords, but the HashAlgorithm class

Asynchronous SHA256 Hashing

妖精的绣舞 提交于 2020-07-06 08:58:24
问题 I have the following method: public static string Sha256Hash(string input) { if(String.IsNullOrEmpty(input)) return String.Empty; using(HashAlgorithm algorithm = new SHA256CryptoServiceProvider()) { byte[] inputBytes = Encoding.UTF8.GetBytes(input); byte[] hashBytes = algorithm.ComputeHash(inputBytes); return BitConverter.ToString(hashBytes).Replace("-", String.Empty); } } Is there a way to make it asynchronous? I was hoping to use the async and await keywords, but the HashAlgorithm class

Async/Await with Vuex dispatch

≡放荡痞女 提交于 2020-07-05 07:10:50
问题 I am making a loader for some components in my app. Here is my component: mounted() { this.loading = true; this.getProduct(); }, methods: { async getProduct() { await this.$store.dispatch('product/getProducts', 'bestseller'); console.log(123); this.loading = false; } }, Vuex action: getProducts({commit}, type) { axios.get(`/api/products/${type}`) .then(res => { let products = res.data; commit('SET_PRODUCTS', {products, type}) }).catch(err => { console.log(err); }) }, The problem is in this

Async/Await with Vuex dispatch

删除回忆录丶 提交于 2020-07-05 07:08:46
问题 I am making a loader for some components in my app. Here is my component: mounted() { this.loading = true; this.getProduct(); }, methods: { async getProduct() { await this.$store.dispatch('product/getProducts', 'bestseller'); console.log(123); this.loading = false; } }, Vuex action: getProducts({commit}, type) { axios.get(`/api/products/${type}`) .then(res => { let products = res.data; commit('SET_PRODUCTS', {products, type}) }).catch(err => { console.log(err); }) }, The problem is in this

Typescript, decorate async function

冷暖自知 提交于 2020-07-05 04:22:10
问题 I'm trying to decorate async function#1 with some async function#2. E.g. function func2(param) { return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => { //make async operations and then return descriptor } @func2(param) async function func1() { await .... //some async operation await .... //some async operation } So, the main idea is to perform some async operation in decorator, and then perform other async calls in the main function. Is it possible to make this withing

Property changed is not updating the UI from inside a task

北慕城南 提交于 2020-07-04 04:19:28
问题 Firstly I have a user control which has a dependency property as follows. The MenuItems property is bound to some List control on the UI. public static readonly DependencyProperty MenuItemsProperty = DependencyProperty.Register( nameof(MenuItems), typeof(IEnumerable<MenuItem>), typeof(MenuViewControl), new PropertyMetadata(null)); public IEnumerable<MenuItem> MenuItems { get => (IEnumerable<MenuItem>)GetValue(MenuItemsProperty); set => SetValue(MenuItemsProperty, value); } The MenuItem class

async is a promise function and with setimeout how it works [duplicate]

江枫思渺然 提交于 2020-07-03 12:56:31
问题 This question already has answers here : Combination of async function + await + setTimeout (10 answers) Is using async in setTimeout valid? (2 answers) Closed 17 days ago . const name = async () => { setTimeout(() => { return Promise.resolve("1") },1000); }; (async function () { console.log("hello2"); })(); const timer = async () => { console.log(await name()); console.log("hello4"); }; timer() expected output hello2 1 hello4 output is hello2 undefined hello4 If i removed the settimeout

MongoError: Topology is closed, please connect

∥☆過路亽.° 提交于 2020-07-03 06:45:35
问题 I'm a front-end dev trying to expand my horizons on a new Next project, learning Node, Mongo, and the server side of GraphQL for the first time. Apollo strikes me as the easiest way to jump in, as I've already used client-side Apollo on previous projects. I've been following the official docs, where I learned of apollo-datasource-mongodb (seemingly the best way to plug my Apollo Server straight into a local Mongo database. Unfortunately there don't seem to be any example repos of this package