Skip to content

Strange bug when sending an object with an async method call to a room #3572

Closed
@brandoncollins7

Description

@brandoncollins7

You want to:

  • report a bug
  • request a feature

Current behaviour

When including an async method call as a property to the emit object, the send goes to everyone regardless of if they are in the room or not.

Steps to reproduce (if the current behaviour is a bug)

Not working:

    let pairs = await db('currency_pairs')
    await Promise.all(
        pairs.map(async p => {
            socket.to(`orderbook-${p.id}`).emit('orderbook', {
                orderbook: await orderbook_service.getOrderbook(p.id),
                pairId: p.id
            })
        })
    )

Working:

    let pairs = await db('currency_pairs')
    await Promise.all(
        pairs.map(async p => {
            let orderbook = await orderbook_service.getOrderbook(p.id)
            socket.to(`orderbook-${p.id}`).emit('orderbook', {
                orderbook,
                pairId: p.id
            })
        })
    )

Expected behaviour

What is expected?

emit should only send to users which have been joined to the room

Setup

  • OS: Windows - Node.js
  • browser:
  • socket.io version:
    2.3.0

Other information (e.g. stacktraces, related issues, suggestions how to fix)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions