cashapp / molecule

Build a StateFlow stream using Jetpack Compose
https://cashapp.github.io/molecule/docs/1.x/
Apache License 2.0
1.87k stars 81 forks source link

Make launchMolecule return a Job? #382

Open IVIanuu opened 7 months ago

IVIanuu commented 7 months ago

It would be nice if launchMolecule would return a Job object to easily cancel it.

JakeWharton commented 7 months ago

How do we do that for the one which returns a StateFlow?

IVIanuu commented 7 months ago

Oh sorry, this makes sense. I only used the overload with the emitter.

JakeWharton commented 7 months ago

We're currently modeled after the Compose APIs which don't offer a job. The best way to get one today is to create a new scope with a dedicated job on which you call launchMolecule.

I would like to return a job, but the StateFlow-returning overload becomes annoying.

IVIanuu commented 7 months ago

This is what i'm doing now, thank you.

JakeWharton commented 7 months ago

I still might make this change for the emitter-based one. We actually were just talking about it internally early last week, coincidentally. For the StateFlow-returning one I could accept a nullable Job, perhaps, as a way to get a handle. Will think about it.