async-await

Do I need to move away from Tokio as I cannot split streams in TLS connections?

↘锁芯ラ 提交于 2020-11-29 11:11:03
问题 I use Tokio to create plain TCP sockets, call tokio::io::split() and the read/write halves get handed to separate threads. They use the async socket read/write APIs with await to accomplish the IO. Our data flow is fairly isolated in the in/out directions, so this model works well in our case. So far so good. Now am looking at adding TLS support on top. Some of the TLS libraries don't allow splitting the stream for various reasons: tokio-rustls (implemented with rustls) allows splitting, but

Do I need to move away from Tokio as I cannot split streams in TLS connections?

本小妞迷上赌 提交于 2020-11-29 11:10:58
问题 I use Tokio to create plain TCP sockets, call tokio::io::split() and the read/write halves get handed to separate threads. They use the async socket read/write APIs with await to accomplish the IO. Our data flow is fairly isolated in the in/out directions, so this model works well in our case. So far so good. Now am looking at adding TLS support on top. Some of the TLS libraries don't allow splitting the stream for various reasons: tokio-rustls (implemented with rustls) allows splitting, but

Do I need to move away from Tokio as I cannot split streams in TLS connections?

为君一笑 提交于 2020-11-29 11:10:39
问题 I use Tokio to create plain TCP sockets, call tokio::io::split() and the read/write halves get handed to separate threads. They use the async socket read/write APIs with await to accomplish the IO. Our data flow is fairly isolated in the in/out directions, so this model works well in our case. So far so good. Now am looking at adding TLS support on top. Some of the TLS libraries don't allow splitting the stream for various reasons: tokio-rustls (implemented with rustls) allows splitting, but

Verify token with API in Angular8 canActivate method of AuthGuard

半城伤御伤魂 提交于 2020-11-29 10:23:46
问题 I want to do some validation on each refresh request for some routes. So I'm using Angular AuthGuard . The problem is in canActivate method I want to perform validation with online API. API is /token/verify which simply gets token variable (jwt) and verify if it's true or false. Then if verify is not complete will route to /login page else do the rest. Here is the code: canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { let token = this.auth

Why does assigning a Task then awaiting it allow to run in parallel

你离开我真会死。 提交于 2020-11-29 09:17:13
问题 I've was playing around with async and I've happened across some behaviour I've not noticed before, if this is a duplicate please let me know, but my google-fu has failed me, mostly because I can't think of decent terms to search: Given a simple async method that does some parameterized work: async Task<String> Foo(int i) { await Task.Delay(i); return i.ToString(); } And a calling method to invoke it in different contexts and bundle the result: async Task<Object> Bar() { var one = Foo(3000);

Why does assigning a Task then awaiting it allow to run in parallel

怎甘沉沦 提交于 2020-11-29 09:17:07
问题 I've was playing around with async and I've happened across some behaviour I've not noticed before, if this is a duplicate please let me know, but my google-fu has failed me, mostly because I can't think of decent terms to search: Given a simple async method that does some parameterized work: async Task<String> Foo(int i) { await Task.Delay(i); return i.ToString(); } And a calling method to invoke it in different contexts and bundle the result: async Task<Object> Bar() { var one = Foo(3000);

Why does assigning a Task then awaiting it allow to run in parallel

假装没事ソ 提交于 2020-11-29 09:17:05
问题 I've was playing around with async and I've happened across some behaviour I've not noticed before, if this is a duplicate please let me know, but my google-fu has failed me, mostly because I can't think of decent terms to search: Given a simple async method that does some parameterized work: async Task<String> Foo(int i) { await Task.Delay(i); return i.ToString(); } And a calling method to invoke it in different contexts and bundle the result: async Task<Object> Bar() { var one = Foo(3000);

How to calculate the execution time of an async function in JavaScript?

蹲街弑〆低调 提交于 2020-11-28 04:51:14
问题 I would like to calculate how long an async function ( async / await ) is taking in JavaScript. One could do: const asyncFunc = async function () {}; const before = Date.now(); asyncFunc().then(() => { const after = Date.now(); console.log(after - before); }); However, this does not work, because promises callbacks are run in a new microtask. I.e. between the end of asyncFunc() and the beginning of then(() => {}) , any already queued microtask will be fired first, and their execution time

How to calculate the execution time of an async function in JavaScript?

左心房为你撑大大i 提交于 2020-11-28 04:50:42
问题 I would like to calculate how long an async function ( async / await ) is taking in JavaScript. One could do: const asyncFunc = async function () {}; const before = Date.now(); asyncFunc().then(() => { const after = Date.now(); console.log(after - before); }); However, this does not work, because promises callbacks are run in a new microtask. I.e. between the end of asyncFunc() and the beginning of then(() => {}) , any already queued microtask will be fired first, and their execution time

How to end Google Speech-to-Text streamingRecognize gracefully and get back the pending text results?

ⅰ亾dé卋堺 提交于 2020-11-25 02:09:11
问题 I'd like to be able to end a Google speech-to-text stream (created with streamingRecognize), and get back the pending SR (speech recognition) results. In a nutshell, the relevant Node.js code: // create SR stream const stream = speechClient.streamingRecognize(request); // observe data event const dataPromise = new Promise(resolve => stream.on('data', resolve)); // observe error event const errorPromise = new Promise((resolve, reject) => stream.on('error', reject)); // observe finish event