|
@@ -1,17 +1,17 @@
|
|
# Async WS:
|
|
# Async WS:
|
|
|
|
|
|
-Almost mirror sample of:
|
|
|
|
|
|
+Almost mirror (front and back) sample of:
|
|
|
|
|
|
Catching data from `Stream` or `WebSocket` and pass it as generated
|
|
Catching data from `Stream` or `WebSocket` and pass it as generated
|
|
sequence of `Promise`s, which can be handled by pseudo synchronous
|
|
sequence of `Promise`s, which can be handled by pseudo synchronous
|
|
`for ... of` or `for await ... of`
|
|
`for ... of` or `for await ... of`
|
|
|
|
|
|
For solve this `Promise` with __outside control__ used. It needed
|
|
For solve this `Promise` with __outside control__ used. It needed
|
|
-because data passed many times to stream ondata/onmessage/onchunk/onfuckingsomethingelse,
|
|
|
|
|
|
+because data passed many times to stream `ondata`/`onmessage`/`onchunk`/`onfuckingsomethingelse` callback
|
|
not only once as in `Promise` callback.
|
|
not only once as in `Promise` callback.
|
|
|
|
|
|
So, promises should be resolved from chunk event outside of
|
|
So, promises should be resolved from chunk event outside of
|
|
-closure, where resolve and reject accessible.
|
|
|
|
|
|
+closure, where `resolve` and `reject` accessible.
|
|
|
|
|
|
When chunk becomes, it saved into chunks queue, and if promise
|
|
When chunk becomes, it saved into chunks queue, and if promise
|
|
for that chunk are already yielded, it resolves
|
|
for that chunk are already yielded, it resolves
|
|
@@ -20,7 +20,7 @@ When promise yielding outside of generator, if chunk for this promise
|
|
already saved in queue, promise resolves with data of that chunk
|
|
already saved in queue, promise resolves with data of that chunk
|
|
|
|
|
|
So, generated promises gives ability to handle stream in imperative
|
|
So, generated promises gives ability to handle stream in imperative
|
|
-manner if `for of` loop with `await`.
|
|
|
|
|
|
+manner using `for of` loop with `await`.
|
|
|
|
|
|
Than, recieved messages passed as JSON with some RPC function call
|
|
Than, recieved messages passed as JSON with some RPC function call
|
|
with params
|
|
with params
|