Created
February 26, 2017 18:45
-
-
Save zainab-ali/f74c9f2540121c50ea2ceedc88d915a7 to your computer and use it in GitHub Desktop.
drone dynamic
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
package drone | |
import fs2._ | |
import java.time.Instant | |
import java.util.UUID | |
object Time { | |
def local: Task[Instant] = Task.delay(Instant.now()) | |
} | |
object Agent { | |
sealed trait Work | |
} | |
trait Agent { | |
def queue(work: Agent.Work): Task[UUID] = ??? | |
def completed: Stream[Task, Agent.Work] = ??? | |
def stop: Task[Unit] = ??? | |
} | |
object Node { | |
type State = List[Agent] | |
} | |
sealed trait Node { | |
def stop: Task[Unit] = ??? | |
} | |
sealed trait Container { | |
def node: Task[Node] = ??? | |
def agent(node: Node): Task[Agent] = ??? | |
} | |
sealed trait Job | |
object Dispatcher { | |
case class State(node: Map[Node, Node.State]) | |
} | |
final class Dispatcher( | |
time: Task[Instant], | |
container: Container, | |
jobs: Stream[Task, Job] | |
) { | |
def run(state: Dispatcher.State): Task[Unit] = { | |
jobs.scan(Task.now(state)) { (current, job) => | |
//Logic using container, etc.. goes here returning a task | |
current | |
}.flatMap(Stream.eval).run | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment