Comments (6)
For what it's worth, when I've done something like what you're doing, I have a thread that has a TChan
for taking requests from the event handler, and a BChan
for sending "responses" back to it in the form of custom events. So I end up with:
- A data type like
Request
that I use to tell the worker thread to do some work over aTChan
, - A custom event type that the worker thread uses to communicate a "response" over a
BChan
, - An event handler case to handle my custom events from the worker thread,
- One or more event handlers that cause work requests to be made to the worker thread over its
TChan
, and - A bit of code to spawn the worker thread before calling
customMain
or whatever brick entry point is being used.
from brick.
a progress bar that increases as a list is traversed
Can you say a bit more about what you mean by "traversed"?
Do you have an application repository that I could look at, to see what you are trying to accomplish?
I tried using a BChan to produce an event on each iteration but that produced this: thread blocked indefinitely in an STM transaction.
This error is not inherent to using a BChan
; it would be triggered by something about the way your thread interactions are working. If I could see your code, that might allow me to spot the issue.
from brick.
I have a processBlock
function that processes a list item and updates the state with the value for the progress bar. I'm mapping this function over a list, but the UI doesn't redraw until the entire call to map
in the event handler finishes, so the progress bar just jumps from 0 to 100.
I tried using a BChan
to try to trigger an internal event:
eventChan <- BC.newBChan 10
let buildVty = VC.mkVty V.defaultConfig
initialVty <- buildVty
void $
M.customMain initialVty buildVty (Just eventChan) theApp $
State
...
eventChan
I figured the easiest way to make the BChan
available to the event handler would be to put it in the state. Inside the processBlock
function, I write an event to the channel, but it produced that "thread blocked" error. Maybe my function is exceeding the 10 event limit?
After thinking about it today, I think it might be possible to get the effect by using the event handler loop itself to iterate over the list, but I think that would still require an internal event, otherwise the user would need to press a key to advance every tick.
from brick.
I figured the easiest way to make the BChan available to the event handler would be to put it in the state.
To confirm, this is indeed a common way to do it.
Inside the processBlock function, I write an event to the channel, but it produced that "thread blocked" error.
If processBlock
is called from within an event handler, that would probably trigger this: the same thread that is doing the reading is also doing the writing. The BChan
should be written to by a background thread that is doing the work.
I think it might be possible to get the effect by using the event handler loop itself to iterate over the list, but I think that would still require an internal event
Yes, that's right. You'll need to make your own custom event type, and give it a constructor like ListProgress ...
. Then add a handler for that event that updates your state's progress bar. Provided the ListProgress
events are coming in at some slow enough interval, then you'll end up with interesting UI behavior. Granted, if you're just wanting to do work you're already doing with map
, then that's likely to be so fast that a custom event won't help you because the progress bar will just go to 100 percent quickly; the assumption that would make it possible to do what you want is that the work actually does take long enough that you have incremental progress to report, i.e., a "tick" equivalent.
from brick.
@khazaddum let me know if there's anything else you need before we can close this.
from brick.
I'll close this since I assume you have what you need, but feel free to open another issue if you need assistance.
from brick.
Related Issues (20)
- row ... now exceeds region width HOT 8
- Is there any way to wait for an input? For example, wait for confirmation. HOT 8
- There should be something like `fmapState`. HOT 10
- Consider adding `zoomOut` for saving lines when dealing with sum types. HOT 3
- Cannot install `brick` via `cabal update && cabal install brick` on NixOS HOT 9
- Add version of customMain that doesn't require a Vty handle HOT 11
- Documentation Unavailable on Hackage HOT 4
- Can you add brick-trading-journal to featured projects on README? HOT 1
- Mouse-based selection stops working after using the mouse in an app. HOT 17
- Visbility request for FormFieldState instead of FormField HOT 7
- Segmentation fault when eagerly pressing a keyboard key HOT 3
- test compilation failure with brick-2.1.1 in Nixpkgs HOT 3
- How can I get SIGTSTP (ctrl-z) to suspend the process? HOT 6
- Thread blocked indefinitely in an STM transaction HOT 35
- Provide absolute coordinates on brick mouse event HOT 5
- How to use dialogSelection with appHandleEvent function? HOT 7
- Pop-up overlay dialog, is it possible? HOT 23
- Keybindings config character uppercase HOT 3
- Add keybindingINIList output to Brick.Keybindings.Pretty HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brick.