ReactiveX / ReactiveX/rxjs

rxjs/webSocket should support deserializer return Promise

Open
#4,270 6 comments 4 reactions 1 assignee View on GitHub

@benlesh is already working on this.

Since Sep 1, 2020.

Dominant language
TypeScript
Stars
31.7k
Forks
3k
PR merge metrics
No merged PRs in 30d

Description

Feature Request

rxjs/webSock should support deserializer return Promise

Is your feature request related to a problem? Please describe.

import { webSocket } from 'rxjs/webSocket'

const api = (options) => {
  const subject = webSocket(options);
  return {
    subscribe: (params: any) => {
      const observableA = subject.multiplex(
        () => params,
        () => ({ close: true }),
        (message: any) =>  {
          return message.requestId === params.requestId
        }
      );

      return observableA
    }
  }
}

const ws = api({
  url: 'ws://127.0.0.1:50055/ws/v2',
  protocol: 'json',
  binaryType: 'blob',
  deserializer: ({ data }) => {
    return new Promise((res, rej) => {
      const reader = new FileReader()
      reader.readAsText(data)
      reader.onload = () => {
        res(JSON.parse(reader.result))
      }
    })
  }
})

ws.subscribe({requestId: '1', data:{}})
  .subscribe((res) => {
    console.log('res', res);
  })

the deserializer have to return Promise because i have to resolve Blob, but socket.onmessage doesn't support deserializer function to return Promise

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.