forked from HeinrichApfelmus/threepenny-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This mode is like `BufferRun`, but will flush the call buffer every 300ms if nonempty.
- Loading branch information
1 parent
5a601f5
commit 1751a45
Showing
7 changed files
with
72 additions
and
47 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
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,50 @@ | ||
{-# LANGUAGE RecordWildCards #-} | ||
module Foreign.JavaScript.CallBuffer where | ||
|
||
import Control.Concurrent | ||
import Control.Concurrent.STM as STM | ||
import Control.Monad | ||
|
||
import Foreign.JavaScript.Types | ||
|
||
{----------------------------------------------------------------------------- | ||
Call Buffer | ||
------------------------------------------------------------------------------} | ||
-- | Set the call buffering mode for the given browser window. | ||
setCallBufferMode :: Window -> CallBufferMode -> IO () | ||
setCallBufferMode w@Window{..} new = do | ||
flushCallBuffer w | ||
atomically $ writeTVar wCallBufferMode new | ||
|
||
-- | Get the call buffering mode for the given browser window. | ||
getCallBufferMode :: Window -> IO CallBufferMode | ||
getCallBufferMode w@Window{..} = atomically $ readTVar wCallBufferMode | ||
|
||
-- | Flush the call buffer, | ||
-- i.e. send all outstanding JavaScript to the client in one single message. | ||
flushCallBuffer :: Window -> IO () | ||
flushCallBuffer w@Window{..} = do | ||
code' <- atomically $ do | ||
code <- readTVar wCallBuffer | ||
writeTVar wCallBuffer id | ||
return code | ||
let code = code' "" | ||
unless (null code) $ | ||
runEval code | ||
|
||
-- Schedule a piece of JavaScript code to be run with `runEval`, | ||
-- depending on the buffering mode | ||
bufferRunEval :: Window -> String -> IO () | ||
bufferRunEval w@Window{..} code = do | ||
action <- atomically $ do | ||
mode <- readTVar wCallBufferMode | ||
case mode of | ||
NoBuffering -> do | ||
return $ Just code | ||
_ -> do | ||
msg <- readTVar wCallBuffer | ||
writeTVar wCallBuffer (msg . (\s -> ";" ++ code ++ s)) | ||
return Nothing | ||
case action of | ||
Nothing -> return () | ||
Just code -> runEval code |
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