Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

clarify how bidirectional communication should work

Abierto
#30 6 comentarios 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 5 días

Nadie ha tomado este issue todavía.

  • #247 de @ting-hong-shieh — cerrado sin fusionar

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Documentación
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
typescript

Línea de trabajo

Comienza con el comportamiento de comunicación bidireccional mostrado en este issue mediante newWebSocketRpcSession, RpcTarget, las funciones de callback y los ejemplos de temporizadores. Revisa el repositorio de ejemplo enlazado para entender el flujo mostrado y documenta los callbacks de estilo notificación y los problemas de async y los temporizadores con ejemplos ejecutables. La tarea estará terminada cuando los recién llegados puedan entender cómo usar la comunicación bidireccional y qué comportamiento temporal esperar.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

documentation

Heya, neat library. Almost what I was asking for just a day ago 😆

I'm having a hard time understanding how to achieve bidirectional communication. It's almost worded like you can just push data back to the client, but I think that's not the right kind of thinking. So I dug deeper I ended up using the functionality that allows you to pass functions by reference- it seems like this is kind of what's intended?

Where it gets really confusing when you add things like timers into the equation. Without marking the method as async and awaiting a promise directly, it doesn't behave as you'd expect (from a "nieve" point of view, that is.)

I have an example repository you can use to explore this in more depth

Example client:

using wsApi = newWebSocketRpcSession<MyWs>("ws://localhost:8000");

const d = (sm: string) => console.log("got something: " + sm)

const wsResult = await wsApi.test(d);

console.log(wsResult);

Example websocket "client":

class WsServer extends RpcTarget {
    async test(fn: (data: string) => void) {
        fn("testing");

        setTimeout(1000, () => {
            fn("hello from timeout");
        });

        return true;
    }
}

It'll call the first function, then return true. That makes a lot of sense! I would expect this to be a "gotcha" here and not a bug of the protocol (how would you know timers are involved?)

Now replace the setTimeout with an import from node:timers/promises:

class WsServer extends RpcTarget {
    async test(fn: (data: string) => void) {
        fn("testing");

        const msg = await setTimeout(1000, "da");
        fn(msg);

        return true;
    }
}

We'll get what we want:

got something: testing
got something: da
true

The ask here is if we can get some examples of bidirectional communication and the "gotchas" those comes with. I can see how functions can be used to achieve the "notification" style API for a client and this is something I'm looking to explore :)

Lenguaje dominante
TypeScript
Estrellas
4k
Forks
150
Merge medio
3 d 12 h
PR fusionados (30 d)
2

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de cloudflare/capnweb

Todos los issues de cloudflare/capnweb

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.