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

Allow creation on background by default on kotlin side #435

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ abstract class RdExtBase : RdReactiveBase() {
val scheduler = when (extThreading) {
ExtThreadingKind.Default -> parentProtocol.scheduler
ExtThreadingKind.CustomScheduler -> CustomExtScheduler()
ExtThreadingKind.AllowBackgroundCreation -> ExtSchedulerWrapper(parentProtocol.scheduler)
ExtThreadingKind.AllowBackgroundCreation -> parentProtocol.scheduler
}

val signal = createExtSignal()
Expand All @@ -86,8 +86,10 @@ abstract class RdExtBase : RdReactiveBase() {
if (scheduler is ExtSchedulerBase && extThreading != ExtThreadingKind.Default)
scheduler.setActiveCurrentThread(activeLifetime)

super.preInit(lifetime, proto)
super.init(lifetime, proto, ctx)
AllowBindingCookie.allowBind {
super.preInit(lifetime, proto)
super.init(lifetime, proto, ctx)
}

val info = ExtCreationInfo(location, (parent as? RdBindableBase)?.containingExt?.rdid, serializationHash, this)

Expand Down Expand Up @@ -172,6 +174,8 @@ abstract class RdExtBase : RdReactiveBase() {
enum class ExtThreadingKind {
Default,
CustomScheduler,

@Deprecated("Creating on the background is allowed by default")
AllowBackgroundCreation
}
}
Expand All @@ -198,23 +202,6 @@ internal abstract class ExtSchedulerBase : IScheduler {
}
}

internal class ExtSchedulerWrapper(val realScheduler: IScheduler) : ExtSchedulerBase() {

override fun queue(action: () -> Unit) {
realScheduler.queue(action)
}

override val isActive: Boolean
get() = realScheduler.isActive || isActiveThread()

override val executionOrder: ExecutionOrder
get() = realScheduler.executionOrder

override fun flush() {
throw InvalidOpenTypeException("Unsupported")
}
}

internal class CustomExtScheduler : ExtSchedulerBase() {
private val locker = Any()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ open class Kotlin11Generator(
enum class ExtThreadingKind {
Default,
CustomScheduler,
@Deprecated("Creating on the background is allowed by default")
AllowBackgroundCreation
}

Expand Down
Loading