Skip to content

Simplify?#6

Closed
lua-vr wants to merge 4 commits intosrid:masterfrom
lua-vr:patch-1
Closed

Simplify?#6
lua-vr wants to merge 4 commits intosrid:masterfrom
lua-vr:patch-1

Conversation

@lua-vr
Copy link
Copy Markdown
Contributor

@lua-vr lua-vr commented Sep 11, 2023

Sorry for almost rewriting the whole thing, but I was trying to fix a small issue in ema and started wondering why lvar could not use the same trick Chan/TChan does to implement the broadcasting instead of doing the ListenerId bookkeeping.

The idea is defining LVar as

data LVar a
  = LVar
      (TMVar a)
      -- ^ A value that changes over time.
      (TVar (TMVar ()))
      -- ^ Gets filled when above gets written to.
      -- Invariant: value is always empty.

the TVar will always point to an empty TMVar, but when the first value gets modified, this empty TMVar is filled (with ()) and the TVar is modified to point to a new empty TMVar.

At this point, the functions listening to the LVar were waiting for the first TMVar to be filled, and when this happens they can proceed to read the new value.

lua-vr and others added 2 commits July 13, 2023 21:58
Package lower bounds should depend on first three numbers (which determine the minimal API set) and upper bounds  should be strict and depent on first two numbers (which determine breaking changes).
@lua-vr
Copy link
Copy Markdown
Contributor Author

lua-vr commented Sep 11, 2023

Oh, and it also fixes the "problem" I started with, namely the fact listenNext would return immediately in the first time it was called with a given ID...

@srid
Copy link
Copy Markdown
Owner

srid commented Sep 11, 2023

@lucasvreis Since this is almost a rewrite, could you add some tests (that mirrors usage in Ema) using hspec ?

Ideally, tests as separate PR which gets merged to master and then we use that in this PR (with whatever additional tests that represent the fixes/changes).

@lua-vr
Copy link
Copy Markdown
Contributor Author

lua-vr commented Jan 31, 2024

@srid I had a look at hspec and my impression was that we're not supposed to run IO actions inside tests... I only saw functions for running IO before or after each test. Perhaps you can try it in emanote? I think it's short enough to understand what it's doing (or at least a fun puzzle to work out 🙃). It's the same mechanism used in TChan.

@srid
Copy link
Copy Markdown
Owner

srid commented Feb 2, 2024

Why not use unsafePerformIO?

@srid
Copy link
Copy Markdown
Owner

srid commented Feb 2, 2024

I think it's short enough to understand what it's doing

Okay, I'll review it latter.

@lua-vr lua-vr closed this Apr 19, 2025
@lua-vr lua-vr deleted the patch-1 branch April 19, 2025 02:48
@srid
Copy link
Copy Markdown
Owner

srid commented Apr 19, 2025

My god, I let this PR slip! Will take a look soonish, @estradilua

@srid srid mentioned this pull request Apr 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants