-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
e0e4ade
commit 03f3573
Showing
9 changed files
with
118 additions
and
72 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module StuntDouble.EventLoop.Event where | ||
|
||
import Control.Concurrent.STM | ||
import Control.Concurrent.Async | ||
|
||
import StuntDouble.Actor | ||
import StuntDouble.Message | ||
import StuntDouble.Reference | ||
|
||
------------------------------------------------------------------------ | ||
|
||
data Event = Command Command | Response Response | Receive Request | ||
|
||
data Command | ||
= Spawn (Message -> Actor) (TMVar LocalRef) | ||
| Invoke LocalRef Message (TMVar Message) | ||
| Send RemoteRef Message | ||
| Quit | ||
|
||
data Response | ||
= IOReady (Async IOResult) | ||
-- Receive (Async Message) Message | ||
|
||
data Request = Request Envelope | ||
|
||
data Envelope = Envelope | ||
{ envelopeSender :: RemoteRef | ||
, envelopeMessage :: Message | ||
, envelopeReceiver :: RemoteRef | ||
} | ||
deriving (Eq, Show, Read) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module StuntDouble.EventLoop.State where | ||
|
||
import Data.Map (Map) | ||
import Control.Concurrent.STM | ||
import Control.Concurrent.Async | ||
|
||
import StuntDouble.EventLoop.Event | ||
import StuntDouble.EventLoop.Transport | ||
import StuntDouble.Actor | ||
import StuntDouble.Reference | ||
import StuntDouble.Message | ||
|
||
------------------------------------------------------------------------ | ||
|
||
|
||
data LoopState = LoopState | ||
{ loopStateAsync :: TMVar (Async ()) -- | Hold the `Async` of the event loop itself. | ||
, loopStateQueue :: TBQueue Event | ||
, loopStateActors :: TVar (Map InternalActorRef (Message -> Actor)) | ||
-- , loopStateHandlers :: TVar (Map (Async Message) (Message -> Actor)) | ||
, loopStateIOHandlers :: TVar (Map (Async IOResult) (InternalActorRef, IOResult -> Actor)) | ||
, loopStateIOAsyncs :: TVar [Async IOResult] | ||
, loopStateTransport :: Transport IO -- Will not change once created, so doesn't need STM? | ||
} |
10 changes: 10 additions & 0 deletions
10
src/runtime-prototype/src/StuntDouble/EventLoop/Transport.hs
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,10 @@ | ||
module StuntDouble.EventLoop.Transport where | ||
|
||
import StuntDouble.EventLoop.Event | ||
|
||
------------------------------------------------------------------------ | ||
|
||
data Transport m = Transport | ||
{ send :: Envelope -> m () | ||
, receive :: m Envelope | ||
} |
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,4 +1,4 @@ | ||
module StuntDouble.Message where | ||
|
||
newtype Message = Message String | ||
deriving (Show, Read) | ||
deriving (Eq, Show, Read) |
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