Skip to content

spawn_listener2 #2471

Closed
Closed

Description

@jesse99

Seeing how there is a comm::select2 I think that it would be useful to have a spawn_listener2. Fwiw the use case I have in mind is a task that allows other tasks to get copies of and mutate state shared by the tasks:

fn manage_state(get_state_port: comm::port<comm::chan<str>>, set_state_port: comm::port<str>)
{
    let mut state = "default";

    loop
    {
        alt comm::select2(get_state_port, set_state_port)
        {
            either::left(channel)
            {
                comm::send(channel, copy(state));
            }
            either::right(new_state)
            {
                state = new_state;
            }
        }
    }
}

Activity

  1. nikomatsakis commented on May 31, 2012

    @nikomatsakis
    Contributor

    why would you use two ports in place of a port with an enum message like:

    enum msg { get(channel), set(value) }
    

    ?

  2. jesse99 commented on Jun 1, 2012

    @jesse99
    ContributorAuthor

    I was trying to leverage the type system so that reader tasks could only read state and writer tasks could only write state. It's probably not that big of a deal though and the code is simpler with an enum like the above.

  3. catamorphism commented on Jun 7, 2012

    @catamorphism
    Contributor

    Closing since it sounds like there's a good workaround for this.

  4. added a commit that references this issue on Sep 22, 2022
  5. added a commit that references this issue on Jun 4, 2024
  6. added a commit that references this issue on Jun 19, 2025
  7. added a commit that references this issue on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions