purescript-contrib / purescript-aff-bus Goto Github PK
View Code? Open in Web Editor NEWMany-to-many broadcasting
License: Apache License 2.0
Many-to-many broadcasting
License: Apache License 2.0
I am building an analog to pipes-concurrency (purescript-pipes-aff), and I am looking for a solution to buffer messages for the producer to read from. Currently bus just gives me a single message and I have to be fast not to miss it. I am wondering what would be involved (and if this would be the right place for this) to buffer a configurable amount of messages with configurable behavior. What I like and appreciate about purescript-aff-bus is the notable absence of FFI calls, leaving that entirely to the purescript-aff library and I think the buffer implementations could and should be implemented similarly. For reference, this is how it's implemented in haskell: https://github.com/Gabriel439/Haskell-Pipes-Concurrency-Library/blob/fccb359dbfb2988da83166d4e2bc6ff01dbe986d/src/Pipes/Concurrent.hs#L177-L198. Any input would be greatly appreciated.
Would be nice if we could avoid the delay before the kill
Note there is a typo interpats
should be interrupts
Hi,
noticed that Aff-Bus is leaking slowly memory in a toy project i have. Here is a minimal working example which shows the leakage quite well (on my machine after 30sec 500MB and rising):
loopy :: BusRW Unit -> Aff _ Unit
loopy bus = do
_ <- Bus.read bus
_ <- forkAff $ loopy bus
Bus.write unit bus
main :: forall e. Eff _ Unit
main = launchAff_ $ do
bus <- Bus.make
_ <- forkAff $ loopy bus
Bus.write unit bus
I have only tested this with node (v8.11.1) not in a browser.
After playing around a bit, i noticed that the problem seems to be the traverse with Either here https://github.com/slamdata/purescript-aff-bus/blob/master/src/Control/Monad/Aff/Bus.purs#L64
Replacing the traverse with pattern-matching seems to fix the problem e.g.
attempt (takeVar cell) >>= case _ of
Left _ -> pure unit
Right res -> do ....
Can anyone confirm the leakage? Is this even a problem in Aff-Bus or is it Aff making problems?
Comment on #6:
This might need to be an unsafe fork (liftEff <<< launchAff) unless you want to let users to control the lifecycle of the loop with supervised.
Based on the logs https://travis-ci.org/slamdata/purescript-aff-bus/builds/343317545#L1237
As I understand that after Bus.kill, execution of Aff stops and never reaches the assertion and log "ok"
Is your change request related to a problem? Please describe.
As described in the documentation section of the Library Guidelines, Contributors libraries are expected to have in their README a short summary of the library's purpose, installation instructions, a quick start with a minimal usage example, and links to the documentation and contributing guide.
This library currently doesn't have a completed quick start in the README.
Describe the solution you'd like
The library needs a quick start section after the installation instructions. argonaut-codecs is one example of a library with a quick start.
Additional context
See the Governance repository for more information about requirements in the Contributors organization.
Is your change request related to a problem? Please describe.
As described in the documentation section of the Library Guidelines, Contributors libraries are expected to have mostly complete module documentation, preferably uploaded to Pursuit.
This library currently doesn't have sufficient module documentation -- several publicly-exported types have no documentation at all.
Describe the solution you'd like
These types all need documentation:
purescript-aff-bus/src/Effect/Aff/Bus.purs
Lines 46 to 58 in 3d6d0de
Once updated, we should tag a release and upload new module documentation to Pursuit so that folks can use it.
Additional context
See the Governance repository for more information about requirements in the Contributors organization.
In some cases you might wanna allow "reader" (read :: Cap
) to be able to kill a bus too.
I'm thinking on something like:
type BusRK = BusR' (kill :: Cap)
split' ∷ ∀ a. BusRW a → Tuple (BusRK a) (BusW a)
.kill ∷ ∀ eff a r. CanKill r => Exn.Error → Bus r a → Aff (avar ∷ AVAR | eff) Unit
, this CanKill
instance will be available for write :: Cap
or kill :: Cap
test_writeInWrite ∷ ∀ eff. Aff (Effects eff) Unit
test_writeInWrite = do
bus ← Bus.make
ref ← liftEff $ newRef false
let
proc = do
res ← Bus.read bus
case res of
1 → Bus.write 2 bus
2 → liftEff (writeRef ref true)
_ → pure unit
proc
f ← forkAff proc
Bus.write 1 bus
assert =<< liftEff (readRef ref)
killFiber (error "Done") f
log "OK"
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.