Skip to content

Commit

Permalink
feat(runtime): add stm transport
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Jun 7, 2021
1 parent bfaa447 commit cede8b6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/runtime-prototype/src/StuntDouble.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ import StuntDouble.Time as X
import StuntDouble.Transport as X
import StuntDouble.Transport.Http as X
import StuntDouble.Transport.NamedPipe as X
import StuntDouble.Transport.Stm as X
15 changes: 15 additions & 0 deletions src/runtime-prototype/src/StuntDouble/Transport/Stm.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module StuntDouble.Transport.Stm where

import Control.Concurrent.STM

import StuntDouble.Transport

------------------------------------------------------------------------

stmTransport :: IO (Transport IO)
stmTransport = do
chan <- newTChanIO
return Transport
{ transportSend = \e -> atomically (writeTChan chan e)
, transportReceive = atomically (readTChan chan)
}
2 changes: 2 additions & 0 deletions src/runtime-prototype/stunt-double.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ library
StuntDouble.Transport
StuntDouble.Transport.Http
StuntDouble.Transport.NamedPipe
StuntDouble.Transport.Stm
StuntDouble.FreeMonad
StuntDouble.Frontend.Http
StuntDouble.Log
Expand Down Expand Up @@ -79,6 +80,7 @@ test-suite test
other-modules:
StuntDouble.ActorMapTest
StuntDouble.Transport.HttpTest
StuntDouble.Transport.StmTest
StuntDouble.Transport.NamedPipeTest
StuntDouble.FrontendTest
StuntDouble.SchedulerTest
Expand Down
18 changes: 18 additions & 0 deletions src/runtime-prototype/test/StuntDouble/Transport/StmTest.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module StuntDouble.Transport.StmTest where

import Control.Concurrent.Async
import Test.HUnit

import StuntDouble

------------------------------------------------------------------------

unit_stmTransport :: IO ()
unit_stmTransport = do
t <- stmTransport
let e = Envelope RequestKind (RemoteRef "from" 0) (InternalMessage "msg")
(RemoteRef "a" 1) 0
a <- async (transportSend t e)
e' <- transportReceive t
cancel a
e' @?= e

0 comments on commit cede8b6

Please sign in to comment.