Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow interpreters to process completion requests asynchronously
- Loading branch information
1 parent
61ee225
commit 483959c
Showing
8 changed files
with
146 additions
and
11 deletions.
There are no files selected for viewing
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
8 changes: 8 additions & 0 deletions
8
modules/shared/interpreter/src/main/scala/almond/interpreter/FutureCompletion.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,8 @@ | ||
package almond.interpreter | ||
|
||
import scala.concurrent.Future | ||
|
||
final case class FutureCompletion( | ||
future: Future[Completion], | ||
cancel: () => Unit | ||
) |
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
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
53 changes: 53 additions & 0 deletions
53
modules/shared/interpreter/src/test/scala/almond/interpreter/IOInterpreterTests.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,53 @@ | ||
package almond.interpreter | ||
|
||
import java.util.concurrent.Executors | ||
|
||
import almond.logger.LoggerContext | ||
import almond.util.ThreadUtil | ||
import cats.implicits._ | ||
import utest._ | ||
|
||
import scala.concurrent.ExecutionContext | ||
|
||
object IOInterpreterTests extends TestSuite { | ||
|
||
private val pool = Executors.newScheduledThreadPool(4, ThreadUtil.daemonThreadFactory("test")) | ||
private val ec = ExecutionContext.fromExecutorService(pool) | ||
|
||
override def utestAfterAll() = { | ||
pool.shutdown() | ||
} | ||
|
||
val tests = Tests { | ||
|
||
"completion" - { | ||
|
||
"cancel previous requests" - { | ||
|
||
val interpreter: Interpreter = new TestInterpreter | ||
val ioInterpreter: IOInterpreter = new InterpreterToIOInterpreter(interpreter, ec, LoggerContext.nop) | ||
|
||
val ios = Seq( | ||
// the "cancel" completions are only completed if they are cancelled | ||
ioInterpreter.complete("cancel"), | ||
ioInterpreter.complete("cancel"), | ||
ioInterpreter.complete("other") | ||
) | ||
|
||
val t = ios.toList.sequence | ||
|
||
val res = t.unsafeRunSync() | ||
val expectedRes = Seq( | ||
Completion(0, "cancel".length, Seq("cancelled")), | ||
Completion(0, "cancel".length, Seq("cancelled")), | ||
Completion("other".length, "other".length, Seq("?")) | ||
) | ||
|
||
assert(res == expectedRes) | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |
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