Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: I'm having trouble getting realtime flow of updates to work #52

Closed
aaronbond opened this issue Jan 30, 2023 · 7 comments
Closed
Assignees
Labels
question Further information is requested realtime

Comments

@aaronbond
Copy link

aaronbond commented Jan 30, 2023

Wondering how to get real time working

quick code snippet:

    private val channel = client.realtime.createChannel("channelId")
    private val messageFlow: Flow<PostgresAction.Insert> = channel.postgresChangeFlow(schemaName) {
        table = messageTableName
    }

    val newMessageFlow: Flow<Message> =
        messageFlow.map {
            it.decodeRecord<ReceiveMessage>()
        }.map { Message(it.content, true) }

    suspend fun init() {
        client.realtime.connect()
        channel.join()
    }

i'm inserting new rows, and putting a breakpoint on it.decodeRecord() but not seeing anything happen. quite new to this so i assume it's probably use error.

@aaronbond aaronbond added the question Further information is requested label Jan 30, 2023
@jan-tennert
Copy link
Collaborator

Did you enable replication for the corresponding table?

https://supabase.com/docs/guides/database/replication

@jan-tennert
Copy link
Collaborator

Also do you collect the actual flow? If not, no data gets passed through. (Learn more here)

@aaronbond
Copy link
Author

yes, replication is enabled and i'm collecting the flow.

I will have a play around with it but if there are no other common issues i'm a bit stumped. I'm trying it on compose desktop if that's relevant. I will look into it further.

@aaronbond aaronbond reopened this Feb 1, 2023
@jan-tennert
Copy link
Collaborator

jan-tennert commented Feb 1, 2023

In Compose you can collect flows as a State using val products by flow.collectAsState(default)
or if you use something like a ViewModel

flow
  .onEach { proccess(it) 
  .launchIn(viewModelScope)

or just collect the flow in a coroutine

@brezinajn
Copy link
Contributor

Had a similar issue few times. You can try restarting the project on Supabase.

@jan-tennert
Copy link
Collaborator

jan-tennert commented Feb 2, 2023

yes, replication is enabled and i'm collecting the flow.

I will have a play around with it but if there are no other common issues i'm a bit stumped. I'm trying it on compose desktop if that's relevant. I will look into it further.

There is now a full demo available which uses Compose Multiplatform.

@jan-tennert
Copy link
Collaborator

jan-tennert commented Feb 13, 2023

Closing due to inactivity. Feel free to reopen this issue, if you need further help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested realtime
Projects
None yet
Development

No branches or pull requests

3 participants