From 59247a4f7a2dc948b3a63ff185c64922eb4334ea Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Mon, 19 Feb 2018 15:09:19 +0100 Subject: refactor(#18): Refactor unused transformation receive methods This change removes the unused transformation receive methods from the `Context` class as this functionality can now be easily implemented in the standard library using the newly introduced `sender` property. --- .../kotlin/com/atlarge/opendc/simulator/Context.kt | 50 +--------------------- 1 file changed, 2 insertions(+), 48 deletions(-) (limited to 'opendc-core') diff --git a/opendc-core/src/main/kotlin/com/atlarge/opendc/simulator/Context.kt b/opendc-core/src/main/kotlin/com/atlarge/opendc/simulator/Context.kt index 24f87eff..b1d635fd 100644 --- a/opendc-core/src/main/kotlin/com/atlarge/opendc/simulator/Context.kt +++ b/opendc-core/src/main/kotlin/com/atlarge/opendc/simulator/Context.kt @@ -117,36 +117,13 @@ interface Context : CoroutineContext.Element { */ suspend fun hold(duration: Duration, queue: Queue) - /** - * Retrieve and remove a single message from the instance's mailbox, suspending the function if the mailbox is - * empty. The execution is resumed after the head of the mailbox is removed after which the message [Envelope] is - * transformed through `transform` to return the transformed result. - * - * @param transform The block to transform the message with in an envelope context, providing access to the sender - * of the message. - * @return The transformed message. - */ - suspend fun receive(transform: suspend Envelope<*>.(Any) -> T): T - - /** - * Retrieve and remove a single message from the instance's mailbox, suspending the function if the mailbox is - * empty. The execution is either resumed after the head of the mailbox is removed after which the message - * [Envelope] is transformed through `transform` to return the transformed result or the timeout has been reached. - * - * @param timeout The duration to wait before resuming execution. - * @param transform The block to transform the message with in an envelope context, providing access to the sender - * of the message. - * @return The processed message or `null` if the timeout was reached. - */ - suspend fun receive(timeout: Duration, transform: suspend Envelope<*>.(Any) -> T): T? - /** * Retrieve and remove a single message from the instance's mailbox, suspending the function if the mailbox is * empty. The execution is resumed after the head of the mailbox is removed and returned. * * @return The received message. */ - suspend fun receive(): Any = receive { it } + suspend fun receive(): Any /** * Retrieve and remove a single message from the instance's mailbox, suspending the function if the mailbox is @@ -155,7 +132,7 @@ interface Context : CoroutineContext.Element { * * @return The received message or `null` if the timeout was reached. */ - suspend fun receive(timeout: Duration): Any? = receive(timeout) { it } + suspend fun receive(timeout: Duration): Any? /** * Send the given message to the specified entity, without providing any guarantees about the actual delivery of @@ -182,29 +159,6 @@ interface Context : CoroutineContext.Element { companion object Key : CoroutineContext.Key> } -/** - * The message envelope that is sent to an [Entity], also containing the metadata of the message. - * - * @param T The shape of the message inside the envelope. - * @author Fabian Mastenbroek (f.s.mastenbroek@student.tudelft.nl) - */ -interface Envelope { - /** - * The message in this envelope. - */ - val message: T - - /** - * The sender of the message. - */ - val sender: Entity<*, *>? - - /** - * The destination of the message. - */ - val destination: Entity<*, *> -} - /** * An [Interrupt] message is sent to an [Entity] process in order to interrupt its suspended state. * -- cgit v1.2.3