Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a proposal for AsyncChannel #216

Merged
merged 1 commit into from
Sep 21, 2023
Merged

Conversation

phausler
Copy link
Member

This proposal formalizes the AsyncChannel and AsyncThrowingChannel types.

Read the full proposal here.

@twittemb
Copy link
Contributor

Hi @phausler should we consider this https://forums.swift.org/t/asyncchannel-should-we-allow-to-buffer/60876/8 for the v1 ?

@phausler
Copy link
Member Author

phausler commented Oct 19, 2022

@twittemb my initial gut reaction is that the buffering variants should be their own types, provided they need a slightly different interface as you were suggesting?

Now if they can be done with the same interface but just some extra knobs/dials on the initialization then perhaps we can add that as a 1.1 improvement?

Particularly for the channel type I want there to be a very easy on-ramp to more complex functionality; as the programmatic understanding becomes more complex the interface can grow in complexity; leaving the more simple concepts more simple to use and the advanced concepts gradually come at the cost of more advance use.

@twittemb
Copy link
Contributor

@phausler I was seeing the same interface with an init(_:) taking a buffer size with a default value.

The send(_:) would still be async but the suspension would be conditioned by the state of the buffer. It will bring complexity in the internal code yes. Perhaps we could introduce an external state machine concept as we did for merge and zip to help with that.

There is still something I'm not sure of (perhaps you can tell): I'm not sure we can "not suspend" at all if the buffer has slots, or if we have to suspend/resume immediately in an atomic operation.

Let's say that we HAVE to suspend/resume immediately (because of the way concurrency is managed with ManagedCriticalState + Continuations), do we still have a benefit (performance wise) ?

@phausler
Copy link
Member Author

Does it make sense to have the default of the init be the 0 case as we have it?

Per the "not suspend" part: it is 100% reasonable to have an async method that conditionally suspends sometimes and not others; after all that is how the AsyncBufferedByteIterator works.

Do you have any prototypes yet of that? TBH AsyncChannel's internals can definitely be optimized (and simplified I think).

For other reasons I would like to step up our proposals to get to a 1.0 asap. So from a delivery standpoint it makes sense to have that as a future direction.

@FranzBusch
Copy link
Member

I left a comment on the forums post. Maybe we can keep the discussion over there to consolidate all views.

@twittemb
Copy link
Contributor

twittemb commented Oct 20, 2022

As a reminder @phausler, we opened this issue a while ago (#148) because some cases were hard to test without "inspecting" the internal behaviour of Channels. The issue is tagged v1.0, so I wonder if we want to tackle that now ?

@twittemb
Copy link
Contributor

twittemb commented Nov 2, 2022

I've added a reply to the thread -> https://forums.swift.org/t/pitch-async-buffered-channel/59854/8 regarding consistency between AsyncChannel and AsyncStream. @phausler @FranzBusch

@twittemb
Copy link
Contributor

Hey @phausler do you have a take on the AsyncChannel / AsyncStream topic ?

@twittemb
Copy link
Contributor

Hi
@phausler can you take a look at #235 where I suggest a new implementation for AsyncChannel?

Thanks.

@soumyamahunt
Copy link

The send method doesn't return the reason for completion, and the producer have no information on what happened to the sent value. For example, yield method on AsyncStream's continuation returns an YieldResult.

Returning similar result based on the return reason:

  • cooperative cancellation
  • channel termination
  • sent value consumed

will help community to use channel building custom data structures.

@FranzBusch
Copy link
Member

This proposal has been accepted. So merging this PR.

@FranzBusch FranzBusch merged commit c889832 into apple:main Sep 21, 2023
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.

5 participants