connectrpc / examples-es

Examples for using Connect with various TypeScript web frameworks and tooling.
https://connectrpc.com/
Apache License 2.0
120 stars 23 forks source link

[Question] Auto reconnect for streams #1716

Closed tahadostifam closed 1 month ago

tahadostifam commented 3 months ago

Is it possible to implement auto reconnect mechanism for connectrpc.com streams with connect-web? If yes, then how?

srikrsna-buf commented 1 month ago

You can write something like this:

const client = createClient(ElizaService, transport);

async function* introduce(req: IntroduceRequest) {
  for (; ;) {
    try {
      yield* client.introduce(req)
    } catch (err) {
      switch (ConnectError.from(err).code) {
        // Codes we don't want to retry
        case Code.InvalidArgument:
        case Code.Unauthenticated:
          throw err;
        default:
        // let the loop continue.
      }
    }
  }
}

const res = introduce({});
tahadostifam commented 1 month ago

Thank you for your reply, I did something similar at @kavkaco.