X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;ds=sidebyside;f=miTask.icl;h=22035410a0995ac6b14150855a17468cc87de405;hb=1c8014ff74afb966b891a4689d8ee3e512300746;hp=84b25633289174f4a0fa15d88c6ef9d3d2ee4b32;hpb=c667554eb5dc359481a5f84b60649169f31e0f3d;p=mTask.git diff --git a/miTask.icl b/miTask.icl index 84b2563..2203541 100644 --- a/miTask.icl +++ b/miTask.icl @@ -7,15 +7,39 @@ from Text import class Text(concat,join,split), instance Text String import iTasks import mTask +derive class iTask MTaskMessage + Start :: *World -> *World -Start world = startEngine mTaskTask world +Start world = startEngine ( + enterInformation "Port Number?" [] + >>= \port->withShared ([], False, [], False) (mTaskTask port) + ) world +//Start world = startEngine mTaskTask world + +mTaskTask :: Int (Shared ([MTaskMessage],Bool,[MTaskMessage],Bool)) -> Task () +mTaskTask port ch = + syncNetworkChannel "localhost" port "\n" decode encode ch ||- + ( + sendMsg msgs ch >>= \_-> + viewSharedInformation "channels" [ViewWith lens] ch @! () + ) >>* [OnAction ActionFinish (always shutDown)] + where + lens :: ([MTaskMessage],Bool,[MTaskMessage],Bool) -> ([String], [String]) + lens (r,_,s,_) = (f r, f s) + where + f [] = [] + f [MTEmpty:xs] = f xs + f [x:xs] = [toString x:f xs] + + msgs = toMessages 500 (toRealByteCode (unMain bc)) -mTaskTask :: Task () -mTaskTask = withShared ([],False,[],False) (\ch-> - syncNetworkChannel "localhost" 8123 "\n" id id ch ||- - updateSharedInformation "channels" [] ch @! ()) + bc :: Main (ByteCode Int Stmt) + bc = sds \x=0 In {main = x =. x +. lit 1 :. pub x} -syncNetworkChannel :: String Int String (String -> m) (m -> String) (Shared ([m],Bool,[m],Bool)) -> Task () | iTask m +sendMsg :: [MTaskMessage] (Shared ([MTaskMessage],Bool,[MTaskMessage],Bool)) -> Task () +sendMsg m ch = upd (\(r,rs,s,ss)->(r,rs,s ++ m,ss)) ch @! () + +syncNetworkChannel :: String Int String (String -> m) (n -> String) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n syncNetworkChannel server port msgSeparator decodeFun encodeFun channel = tcpconnect server port channel {ConnectionHandlers|onConnect=onConnect,whileConnected=whileConnected,onDisconnect=onDisconnect} @! () where @@ -33,17 +57,17 @@ syncNetworkChannel server port msgSeparator decodeFun encodeFun channel onDisconnect l (received,receiveStopped,send,sendStopped) = (Ok l,Just (received,True,send,sendStopped)) -consumeNetworkStream :: ([m] -> Task ()) (Shared ([m],Bool,[m],Bool)) -> Task () | iTask m -consumeNetworkStream processTask channel - = ((watch channel >>* [OnValue (ifValue ifProcess process)]) >| if (isEmpty received) (return ()) (processTask received) - @! receiveStopped - - empty :: ([m],Bool,[m],Bool) -> ([m],Bool,[m],Bool) - empty (_,rs,s,ss) = ([],rs,s,ss) +//consumeNetworkStream :: ([m] -> Task ()) (Shared ([m],Bool,[n],Bool)) -> Task () | iTask m & iTask n +//consumeNetworkStream processTask channel +// = ((watch channel >>* [OnValue (ifValue ifProcess process)]) >| if (isEmpty received) (return ()) (processTask received) +// @! receiveStopped +// +// empty :: ([m],Bool,[m],Bool) -> ([m],Bool,[m],Bool) +// empty (_,rs,s,ss) = ([],rs,s,ss)