async-await

Call file from another method

青春壹個敷衍的年華 提交于 2020-01-17 08:27:38
问题 Newbie question here. I have this file picker: public async void PickImage() { FileOpenPicker ImagePicker = new FileOpenPicker(); ... StorageFile file = await ImagePicker.PickSingleFileAsync(); // ... } And I want to use the file set by this image picker in another method. Something like this: private async void CreateButton_Click(object sender, RoutedEventArgs e) { ... the one from PickImage() v StorageFile copyImage = await file.CopyAsync(DateTimeFolder, "image", NameCollisionOption

Is it safe to subscribe to an observable with an async function

泄露秘密 提交于 2020-01-17 01:49:24
问题 I have an event emitter that sends events at 50Hz. I'd like to subscribe to this emitter with an async method. The code looks like the following: this.emitter = fromEventPattern(this.addHandler, this.removeHandler, (err, char) => [err, char]); this.rxSubscription = this.emitter.subscribe(this.handleUpdatedValuesComingFromSensor); and handleUpdatedValuesComingFromSensor = async (arr: any[]): Promise<void> => { ... await someMethodAsync(); ... } I maybe wrong but I'm under the impression that

Return Task<T> as plain Task breaks WebAPI

限于喜欢 提交于 2020-01-16 20:06:15
问题 This is actually a different angel on this question Task with result unknown type Consider this code public interface IQueryHandler<in TQuery, TResult> where TQuery : Query<TResult> { Task<TResult> Handle(TQuery query); } Above interface is invoked like where Task<T> will be exposed as Task public Task Invoke(Query query) { var queryHandlerType = typeof(IQueryHandler<,>); var queryType = query.GetType(); var queryResultType = queryType.BaseType.GetGenericArguments().First(); var handler =

Return Task<T> as plain Task breaks WebAPI

爷,独闯天下 提交于 2020-01-16 20:06:05
问题 This is actually a different angel on this question Task with result unknown type Consider this code public interface IQueryHandler<in TQuery, TResult> where TQuery : Query<TResult> { Task<TResult> Handle(TQuery query); } Above interface is invoked like where Task<T> will be exposed as Task public Task Invoke(Query query) { var queryHandlerType = typeof(IQueryHandler<,>); var queryType = query.GetType(); var queryResultType = queryType.BaseType.GetGenericArguments().First(); var handler =

Is it a reasonable approach for lock-free design for this scenario

青春壹個敷衍的年華 提交于 2020-01-16 18:13:32
问题 This is kind of follow up to one of my earlier question here. In summary I am trying to come up with a lock free design for this scenario where I upon cancellation of task I want to call a method of third party library. In response to my question, a helpful SO participant suggested to use CancellationToken.Register but I am not sure where and how can I use that here. Below is code that I come up with. Please let me know if you see any issue with this approach or if there are any better

Strange observation on nodejs infinite loop function execution

╄→尐↘猪︶ㄣ 提交于 2020-01-16 18:03:52
问题 I recently came across the article Tail call optimization in ECMAScript 6. I was interested in testing the TCO behavior (Even though I later found that the TCO was not supported by nodejs 8+ as mentioned by the article) and found behavior that I could not understand. Plain loop function 'use strict'; process.on('SIGTERM', () => { console.log('SIGTERM received'); process.exit(0); }) process.on('SIGINT', () => { console.log('SIGINT received'); process.exit(0); }) process.on('uncaughtException',

koa and sqlite3 node REST endpoint returning only Database object instead of data

时光总嘲笑我的痴心妄想 提交于 2020-01-16 16:26:08
问题 I have a simple GET route setup with Koa and sql3lite that fetches from a json file some data, with the use of a wrapper. A helper sql3lite wrapper exposes an initialize function for the main server index.js file to load into memory on startup: index.js const data = require('./data'); data.initialize(); const server = createServer(); server.listen(PORT, () => { console.log(`server listening on port ${PORT}`); }); The data.js file serves as a wrapper around the sqlite3 node library, so routes

koa and sqlite3 node REST endpoint returning only Database object instead of data

久未见 提交于 2020-01-16 16:25:20
问题 I have a simple GET route setup with Koa and sql3lite that fetches from a json file some data, with the use of a wrapper. A helper sql3lite wrapper exposes an initialize function for the main server index.js file to load into memory on startup: index.js const data = require('./data'); data.initialize(); const server = createServer(); server.listen(PORT, () => { console.log(`server listening on port ${PORT}`); }); The data.js file serves as a wrapper around the sqlite3 node library, so routes

Wrap synchronous code into async await in disconnected scenario

与世无争的帅哥 提交于 2020-01-16 14:49:08
问题 I have the following client-server style pseudo-code: public void GetGrades() { var msg = new Message(...); // request in here QueueRequest?.Invoke(this, msg); // add to outgoing queue } In another processor class I have a loop : // check for messages back from server // server response could be a "wait", if so, wait for real response // raise MessageReceived event here // each message is then processed by classes which catch the event // send new messages to server if (queue.Any()){ var msg

Creating an async singletone in javascript

安稳与你 提交于 2020-01-16 08:36:23
问题 I need to implement an async singleton, that creates a single instance of a class that requires asynchronous operations in order to pass arguments to the constructor. I have the following code: class AsyncComp { constructor(x, y) { this.x = x; this.y = y; } // A factory method for creating the async instance static async createAsyncInstance() { const info = await someAsyncFunction(); return new AsyncComp(info.x, info.y); } // The singleton method static getAsyncCompInstance() { if