-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
98 additions
and
26 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
kyo-core/js/src/main/scala/kyo/KyoAppPlatformSpecific.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package kyo | ||
|
||
import kyo.Maybe.Absent | ||
import kyo.Maybe.Present | ||
|
||
abstract class KyoAppPlatformSpecific extends KyoApp.Base[Async & Resource & Abort[Throwable]]: | ||
|
||
private var maybePreviousAsync: Maybe[Unit < (Async & Abort[Throwable])] = Absent | ||
|
||
final override protected def run[A: Flat](v: => A < (Async & Resource & Abort[Throwable]))(using Frame): Unit = | ||
import AllowUnsafe.embrace.danger | ||
val currentAsync: Unit < (Async & Abort[Throwable]) = | ||
Abort.run(handle(v)).map(result => IO(printResult(result)).andThen(Abort.get(result)).unit) | ||
maybePreviousAsync = maybePreviousAsync match | ||
case Absent => Present(currentAsync) | ||
case Present(previousAsync) => Present(previousAsync.map(_ => currentAsync)) | ||
initCode = maybePreviousAsync.map { previousAsync => () => | ||
val racedAsyncIO = Clock.repeatWithDelay(2.seconds)({ | ||
println("repeating") | ||
}).map { fiber => | ||
val race = Async.race(Seq(fiber.get, previousAsync)) | ||
Async.timeout(timeout)(race) | ||
} | ||
val _ = IO.Unsafe.run(Async.run(racedAsyncIO)).eval | ||
}.toList | ||
end run | ||
|
||
end KyoAppPlatformSpecific |
15 changes: 15 additions & 0 deletions
15
kyo-core/jvm/src/main/scala/kyo/KyoAppPlatformSpecific.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package kyo | ||
|
||
import scala.collection.mutable.ListBuffer | ||
|
||
abstract class KyoAppPlatformSpecific extends KyoApp.Base[Async & Resource & Abort[Throwable]]: | ||
|
||
final override protected def run[A: Flat](v: => A < (Async & Resource & Abort[Throwable]))(using Frame): Unit = | ||
import AllowUnsafe.embrace.danger | ||
initCode = initCode.appended(() => | ||
val result = IO.Unsafe.run(Abort.run(Async.runAndBlock(timeout)(handle(v)))).eval | ||
printResult(result) | ||
) | ||
end run | ||
|
||
end KyoAppPlatformSpecific |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 0 additions & 7 deletions
7
kyo-scheduler/js/src/main/scala/java/util/concurrent/ThreadFactory.scala
This file was deleted.
Oops, something went wrong.
10 changes: 6 additions & 4 deletions
10
kyo-scheduler/js/src/main/scala/kyo/scheduler/util/Threads.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
package kyo.scheduler.util | ||
|
||
import java.lang.Thread | ||
import java.util.concurrent.ThreadFactory | ||
import java.util.concurrent.ThreadFactoryStub | ||
|
||
object Threads { | ||
|
||
def apply(name: String): ThreadFactory = | ||
ThreadFactoryStub.get | ||
def apply(name: String): ThreadFactory = apply(name, _ => Thread.currentThread()) | ||
|
||
def apply(name: String, create: Runnable => Thread): ThreadFactory = | ||
ThreadFactoryStub.get | ||
new ThreadFactory { | ||
override def newThread(runnable: Runnable): Thread = create(runnable) | ||
} | ||
|
||
} |