Comments (3)
This poses another question: yielding to a bare object is really cool and pretty to look at but a little confusing to understand. For example yielding to a stream to create a subscription:
function*() {
const subscription = yield* stream;
}
I wonder if it would be easier for end-users to grok something more like this:
function*() {
const subscription = yield* stream();
// or
const subscription = yield* stream.subscription();
}
Just thinking through the implications of this API change as well as being consistent across-the-board.
from effection.
This is a really interesting point. So basically, you're saying that a stream should be:
type Stream<T, TClose> = () => Operation<Subscription<T, TClose>>;
Or rather stream should stay the same, and that the convention should be to return functions that return them? For example that the type of something likeChannel
should be:
interface Channel<T, TClose> {
//...
stream(): Stream<T,TClose>;
}
because at the end of the day, a Stream is really just a very specific kind of resource.
I'd almost say that the right call is to have Channel
be something like:
interface Channel<T, TClose> {
send(value: T): Operation<void>;
close(value: TClose): Operation<void>;
subscribe(): Stream<T, TClose>;
}
Which is confusing, but makes sense when you think of what a stream really is which is just an operation that yields a subscription. If we expand the type, it makes more sense.
interface Channel<T, TClose> {
send(value: T): Operation<void>;
close(value: TClose): Operation<void>;
subscribe(): Operation<Subscription<T, TClose>>;
}
Maybe that's the answer?
from effection.
Another option is to make the Stream
interface:
interface Stream<T, TClose> {
subscribe(): Operation<Subscription<T, TClose>>;
}
It's a very small change, but it might reduce confusion by quite a bit. Everything would continue to work the same, but instead of saying yield* stream
, you would just say yield* stream.subscribe()
yield* each(stream)
would continue continue to work, but any time you're manually iterating a stream it would be a bit less confusing.
from effection.
Related Issues (20)
- Add guide for using Context + Effects
- Finalize v3 docs HOT 1
- Determine order of operations for spawned code HOT 1
- Revisit having `Scope.run()` crash the frame if error leaks out of operation HOT 1
- 3.0 Public API review
- Effection examples HOT 2
- Unexpected return type for `all()` HOT 5
- Add ability to evaluate append an operation to the current frame
- Write a tutorial about "Build an Autocomplete with Structured Concurrency using Effection in React" HOT 19
- Reorganize Effection Documentation HOT 8
- How to delay abort/process shutdown? HOT 4
- RFC: Cultivate an Effection ecosystem with a contrib mono repository
- RFC: Embed API documentation into website
- imports not used when using multi-root workspaces for website development in VSCode HOT 2
- `.all()` creates a new Scope HOT 2
- add `allSettled()` operation congruent with `Promise.allSettled()`
- "finally" cleanup code not guaranteed to run in the correct order HOT 2
- add `withResolvers()` utility to be the analog of `Promise.withResolvers()`
- Docs typos HOT 5
- Please enable dark theme on web site
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 effection.