Nessuna descrizione

Ivan Asmer db1045030f react friendly 5 anni fa
public 9457098217 cors 5 anni fa
README.md 7473dc53e3 MD 5 anni fa
index.js db1045030f react friendly 5 anni fa
package-lock.json 9457098217 cors 5 anni fa
package.json 9457098217 cors 5 anni fa

README.md

Async WS:

Almost mirror (front and back) sample of:

Catching data from Stream or WebSocket and pass it as generated sequence of Promises, which can be handled by pseudo synchronous for ... of or for await ... of

For solve this Promise with outside control used. It needed because data passed many times to stream ondata/onmessage/onchunk/onfuckingsomethingelse callback not only once as in Promise callback.

So, promises should be resolved from chunk event outside of closure, where resolve and reject accessible.

When chunk becomes, it saved into chunks queue, and if promise for that chunk are already yielded, it resolves

When promise yielding outside of generator, if chunk for this promise already saved in queue, promise resolves with data of that chunk

So, generated promises gives ability to handle stream in imperative manner using for of loop with await.

Than, recieved messages passed as JSON with some RPC function call with params