zishang520/socket.io

support for acknowledgements

Closed this issue · 3 comments

support for socket.io's request-response "acknowledgements", which allows for an optional callback at the end of an event listeners parameters ( more at https://socket.io/docs/v4/emitting-events ). Unless there is already a existing api that this library uses which does something similar, in which case could I please be redirected to what i need to use for it.

There are some issues with this feature and it doesn't work properly. Please be patient with my next release to fix it.

Hello, v1.0.17 can be used normally, the following is the code snippet:
server:

io.On("connection", func(clients ...any) {
    client := clients[0].(*socket.Socket)
    client.On("chat message", func(msgs ...any) {
        // Send
        client.Timeout(3*time.Second).Emit("chat message", map[string]any{
            "message": types.NewStringBufferString("test"),
        }, func(anys ...any) {
            utils.Log().Success("message %v", anys)
        })
    })
    client.On("update item", func(anys ...any) {
        anys[2].(func(...any))(map[string]string{
            "status": "ok",
        })
        utils.Log().Success("update item %v", anys)
    })
})

client:

socket.timeout(3000).emit("update item", "1", { name: "updated" }, (err, response) => {
    console.log(err); // null or new Error
    console.log(response.status); // ok
});
socket.on('chat message', (msg, callback) => {
    callback({
        aa: 1
    })
});

For other usage methods, please refer to the official documentation of socket.io. Thanks for your support.

Do you have any other questions? No more questions this question will be closed.