Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Start cleaning up Supply design/implementation.
This commit substantially refactors how supplies work on the inside,
along with a couple of API changes to deal with design issues.

Supply is now much more like Seq, in that it's a container around a
large number of implementations. Those implementations now do the
Tappable role. Tapping a Supply still returns a Tap, but now it only
has a .close method. A Supply no longer has a list of taps; it's just
something that can be tapped. This allows for far cleaner and more
efficient implementation of the Supply combinators. More importantly,
it removes the design issues that rogue code could in theory take
any Supply and emit values into it.

Creating an on-demand Supply is now the role of a separate class, at
present called Publisher, name subject to review. A Publisher has a
Supply method to obtain a Supply. The Supply can be tapped many times,
and the Publisher used to emit/done/quit to all those tappers (thus
making it the typical way to do live supplies). Code can therefore
expose a Supply, but keep the right to publish values to itself, which
will be more robust.

The on meta-combinator is gone, in favor of using supply blocks. Some
of the built-in combinators using on have been rewritten in terms of
Supply blocks. A number remain to be refactored.

Finally, the notion of serial and sane supplies has been introduced.
A serial supply promises it'll never emit more than one value at a
time. A sane supply promises it'll follow the Supply protocol, that
is [emit* [done|quit]], and in addition implies serial. All of the
built-in combinators provide sanity; Publisher also enforces this,
but does provide an escape hatch just in case. This simplifies the
implementation of many combinators, and will also help prevent a
number of situations that existed before where it was all too easy to
write code using supplies that had data races.
supplies writing data races into their code.
  • Loading branch information
jnthn committed Nov 25, 2015
1 parent 2e38ba6 commit 461ceab
Show file tree
Hide file tree
Showing 5 changed files with 1,318 additions and 1,371 deletions.
2 changes: 1 addition & 1 deletion src/core/List.pm
Expand Up @@ -3,7 +3,7 @@ my class X::TypeCheck { ... }
my class X::TypeCheck::Splice { ... }
my class X::Cannot::Lazy { ... }
my class X::Cannot::Empty { ... }
my role Supply { ... }
my class Supply { ... }

my sub combinations(\n, \k) {
return ((),) if k < 1;
Expand Down

0 comments on commit 461ceab

Please sign in to comment.