Raphael TEYSSANDIER
11/29/2022, 8:03 PMpublic final Object connectLocal(@NotNull final Credential.LocalMode credential, @NotNull final List features, @NotNull final Function1 configuration, @NotNull Continuation $completion) {
return FlowKt.callbackFlow((Function2)(new Function2((Continuation)null) {
...
};
The last argument isn’t used, but in callbackFlow
we pass null instead of the completion. Any idea ?Rick Clephas
11/29/2022, 8:12 PMnull
continuation is provided. However callbackFlow
itself isn’t a suspend function, therefor it doesn’t accept a continuation (which is why the last argument isn’t used). The block
parameter of the callbackFlow
is a suspend function, which is why it should receive a continuation from the Flow
implementation (I am guessing that that’s probably why you are seeing this continuation argument).Raphael TEYSSANDIER
11/29/2022, 8:14 PMXXXX.INSTANCE.connectLocal(
new Credential.LocalMode(""),
Feature.Companion.getDefaultFeatures(),
XXXXHelper.createSessionDefinition(
new Server(
Server.Scheme.HTTPS,
"<http://xxx.com|xxx.com>",
Server.Endpoint.defaultOnlineEndpoint()
)
),
new Continuation<Flow<? extends InitStep>>() {
@NotNull
@Override
public CoroutineContext getContext() {
return EmptyCoroutineContext.INSTANCE;
}
@Override
public void resumeWith(@NotNull Object o) {
}
}
);
Rick Clephas
11/29/2022, 8:25 PMconnectLocal
it just returns the Flow
from callbackFlow
.
callbackFlow
returns a cold flow, so you would need to collect it before any code inside the block
is executed.Raphael TEYSSANDIER
11/29/2022, 8:48 PMif (test instanceof Flow) {
((Flow<?>) test).collect(
(FlowCollector<Object>) (o, continuation) -> null,
new Continuation<Unit>() {
@NotNull
@Override
public CoroutineContext getContext() {
return EmptyCoroutineContext.INSTANCE;
}
@Override
public void resumeWith(@NotNull Object o) {
System.out.println(o);
}
}
);
}
But nothing is printedRick Clephas
11/29/2022, 8:57 PMconnectLocal
functions? I am starting to wonder why it accepts a continuation if it returns the Flow directly 🤔Raphael TEYSSANDIER
11/29/2022, 8:58 PMsuspend fun connectLocal(
credential: Credential.LocalMode,
features: List<Feature> = Feature.getDefaultFeatures(),
configuration: LocalSessionConfiguration.() -> Unit
): Flow<InitStep> = callbackFlow {
val uuid = EPPlatform.randomUUID()
val config = LocalSessionConfiguration().apply(configuration)
val parentJob = Job() // improve for better error handling -> Todo for later
val session = Session.create(uuid, SessionMode.LOCAL)
val scope = session.scope
val client: HttpClient = buildClient(
config = config, localConfiguration = config.localConfiguration
)
scope.declare(client)
koinApp.koin.declare(LoginAndSessionService(client = client))
scope.baseDI(client = client)
val sortedFeatures = scope.initFeatures(features, client, config)
scope.get<GatewayRepository>()
.setLocalToken(credential.token)
.exceptionOrNull()
trySend(InitStep.Authenticated)
initFetchFeatures(sortedFeatures, scope, config.mode, parentJob).join()
success(session = session, startPoller = config.startPoller)
awaitClose { parentJob.complete() }
}
Rick Clephas
11/29/2022, 9:12 PMtest
variable comming from? Could you verify if resumeWith
for your connectLocal
call is being called with a Flow? Also is the code inside the callbackFlow
ever called?Raphael TEYSSANDIER
11/29/2022, 9:20 PMtest
variable is just the return of connectLocal
. I don’t how to verify, I can put break point inside the decompiled class. Yeah, the method is working in a Android AppRick Clephas
11/29/2022, 9:31 PMtest
to verify you are actually receiving the Flow.
If test is indeed the Flow then I think the only remaining issue is in the other print statement.
You are currently printing the result of the collect
. Which is probably not going to be called (I don't see any close
call inside the callbackFlow
). Try logging o
from the first argument (FlowCollector
).Rick Clephas
11/29/2022, 9:34 PMRaphael TEYSSANDIER
11/29/2022, 9:36 PMtest = block[kotlinx.coroutines.channels.ProducerScope<com.modulotech.epos.session.InitStep>.() -> kotlin.Unit] -> CallbackFlowBuilder[capacity=-2]
The flow collector is not called, nothing is print out.
I would like to stay full kotlin.Rick Clephas
11/29/2022, 9:43 PMo
inside resumeWith
of the connectLocal
call?Raphael TEYSSANDIER
11/29/2022, 9:46 PMtest instanceOf Flow
is true
.
I have put in every resumeWith
a println, but nothing is printed.
Maybe it’s because it’s not launch in a Coroutine ?Rick Clephas
11/29/2022, 9:52 PMfun connectLocal(...., onItem: (InitStep) -> Unit) {
coroutineScope.launch {
connectLocal(....).collect { onItem(it) }
}
}
Raphael TEYSSANDIER
11/29/2022, 9:58 PM