0

I am trying to implement a chat client with a function Listen() which is forever listening to incoming messages. In my exposed function I convert a channel by iterating over everything it sends and forwarding it with a callback by the receiver (eg Kotlin).

func (c *Chat) Listen(receiver MessageReceiver) error {
        return c.auth.WithToken(func(token string) error {
                ch, err := c.repo.Listen(token)
                if err != nil {
                        return err
                }
                for msg := range ch {
                        receiver.Add(&Message{
                                From:    msg.From,
                                Content: msg.Content,
                        })
                }
                return nil
        })
}

When I call this in Kotlin I would like to transform it to a flow - but I have some problems with the load on the main thread - and is constantly getting messages about missing frames on the main thread.

fun listen() = channelFlow {
    chat.listen {
        trySendBlocking(Message(it.content, it.from, MessageType.IN))
    }
}

Does anyone know how to deal with this type of usecase of gomobile (bind) ?

mama
  • 2,046
  • 1
  • 7
  • 24

0 Answers0