Skip to content

Commit

Permalink
Merge pull request #435 from JetBrains/background-creation-ext-usov
Browse files Browse the repository at this point in the history
Allow creation on background by default on kotlin side
  • Loading branch information
Iliya-usov authored Sep 4, 2023
2 parents eade162 + 834999a commit a1e1ee8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 20 deletions.
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

0 comments on commit a1e1ee8

Please sign in to comment.