I'm writing a chat powered by twilio API. I have a problem with creating a channel and then obtaining all of its members.
The flow is following:
- Frontend hits an endpoint on the backend which is responsible for creating a channel
- Backend creates a channel
- On the Frontend I receive event
channelAdded
(this is from twilio sdk) - In the event callback I receive a channel as an argument
- I call
.getMembers()
method on this newly created channel
And... the problem is that this method returns wrong number of members. I created a channel with 5 members, but the method returned only 3 of them. After I refresh the page everything works as expected - .getMembers()
returns 5 members. It looks like there might be some race conditions somewhere. I could "wait" on every new channel a second or two - it feels very hacky, but probably solves this issue.
Am I doing something wrong?