{"id":20315229,"url":"https://github.com/sysread/promises-channel","last_synced_at":"2026-05-28T13:31:20.849Z","repository":{"id":59149708,"uuid":"162445763","full_name":"sysread/Promises-Channel","owner":"sysread","description":"A coordination channel implemented with Promises","archived":false,"fork":false,"pushed_at":"2019-07-05T18:37:38.000Z","size":28,"stargazers_count":0,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-24T05:58:45.013Z","etag":null,"topics":["channel","perl","promise","promises"],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sysread.png","metadata":{"files":{"readme":"README.pod","changelog":"Changes","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-19T14:03:25.000Z","updated_at":"2019-07-05T18:37:40.000Z","dependencies_parsed_at":"2022-09-13T08:42:17.524Z","dependency_job_id":null,"html_url":"https://github.com/sysread/Promises-Channel","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysread%2FPromises-Channel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysread%2FPromises-Channel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysread%2FPromises-Channel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sysread%2FPromises-Channel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sysread","download_url":"https://codeload.github.com/sysread/Promises-Channel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241818874,"owners_count":20025210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["channel","perl","promise","promises"],"created_at":"2024-11-14T18:18:23.520Z","updated_at":"2026-05-28T13:31:20.842Z","avatar_url":"https://github.com/sysread.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"=pod\n\n=encoding UTF-8\n\n=head1 NAME\n\nPromises::Channel - a coordination channel implemented with Promises\n\n=head1 VERSION\n\nversion 0.05\n\n=head1 SYNOPSIS\n\n  # See notes about recursion in Promises::Cookbook::Recursion\n  use Promises backend =\u003e ['AE'], 'deferred';\n  use Promises::Channel qw(channel);\n\n  my $channel = channel\n    limit =\u003e 4;\n\n\n  # Use $channel to invert control on an AnyEvent::Handle\n  $ae_handle-\u003eon_read(sub {\n    my $handle = shift;\n\n    $handle-\u003epush_read(line =\u003e sub {\n      my ($handle, $line) = @_;\n      $channel-\u003eput($line);\n    });\n  });\n\n  $ae_handle-\u003eon_error(sub {\n    $channel-\u003eshutdown;\n  });\n\n  my $depleted = 0;\n  $channel-\u003eon_shutdown\n    -\u003ethen(sub { $depleted = 1 });\n\n  sub reader {\n    my ($channel, $line) = @_;\n    do_stuff $line;\n\n    # Queue the next read, using done to avoid recursion\n    $channel-\u003eget-\u003edone(\\\u0026reader);\n  }\n\n  $channel-\u003eget-\u003ethen(\\\u0026reader);\n\n=head1 DESCRIPTION\n\nA C\u003cPromises::Channel\u003e is a FIFO queue that produces L\u003cPromises::Promise\u003es\nwhich resolve to the items added to the queue.\n\n=head1 ATTRIBUTES\n\n=head2 limit\n\nSets an upper boundary on the number of items which may be queued at a time. If\nthis limit is reached, the promise returned by the next call to L\u003c/put\u003e will\nnot be resolved until there has been a corresponding call to L\u003c/get\u003e (or the\nchannel has been L\u003c/shutdown\u003e.\n\nNote that decreasing the limit does not retroactively apply to items already\nqueued, meaning that new callers L\u003c/put\u003e will block until the queue has been\ndrained sufficiently.\n\n=head2 is_shutdown\n\nReturns true if the channel has been shutdown. The channel will be\nautomatically shutdown and drained when demolished.\n\n=head1 METHODS\n\n=head2 size\n\nReturns the number of items in the queue. This number is not adjusted to\nreflect any queued waiters.\n\n=head2 is_full\n\nIf a L\u003c/limit\u003e has been set, returns true if the channel is full and cannot\nimmediately accept new items.\n\n=head2 is_empty\n\nReturns true if there are no items in the queue and there are no pending\ndeliveries of items from deferred L\u003c/put\u003es.\n\n=head2 put\n\nAdds one or more items to the channel and returns a L\u003cPromises::Promise\u003e that\nwill resolve to the channel instance after the item has been added (which may\nbe deferred if L\u003c/limit\u003e has been set).\n\n=head2 get\n\nReturns a L\u003cPromises::Promise\u003e which will resolve to the channel and the next\nitem queued in the channel.\n\n  $chan-\u003eget-\u003ethen(sub {\n    my ($chan, $item) = @_;\n    ...\n  });\n\n=head2 shutdown\n\nCloses the queue. This does not prevent new items from being added. However,\nfuture calls to L\u003c/get\u003e will be resolved immediately with C\u003cundef\u003e. Any\npreviously deferred calls to get will be immediately resolved until the channel\nis empty, after which any remaining deferrals will be resolved with C\u003cundef\u003e.\n\nWhen the channel goes out of scope, it will be shutdown and drained\nautomatically.\n\n=head2 on_shutdown\n\nReturns a promise which will be resolved after the channel has been shut down\nand drained. As the channel is shut down when demolished, this promise will\nbe resolved when the channel goes out of scope as well.\n\n=head1 EXPORTS\n\nNothing is exported by default.\n\n=head2 chan\n\n=head2 channel\n\nSugar for calling the default constructor. The following lines are equivalent.\n\n  my $ch = chan;\n  my $ch = channel;\n  my $ch = Promises::Channel-\u003enew;\n\n=head2 merge\n\nCreates a new merged channel from the supplied L\u003cPromises::Channel\u003e instances.\nSee L\u003cPromises::Channel::Merged\u003e for a detailed explanation.\n\n=head1 CONTRIBUTORS\n\nThe following people have contributed to this module by supplying new features,\nbug reports, or feature requests.\n\n=over\n\n=item Erik Huelsmann (EHUELS)\n\n=back\n\n=head1 AUTHOR\n\nJeff Ober \u003csysread@fastmail.fm\u003e\n\n=head1 COPYRIGHT AND LICENSE\n\nThis software is copyright (c) 2019 by Jeff Ober.\n\nThis is free software; you can redistribute it and/or modify it under\nthe same terms as the Perl 5 programming language system itself.\n\n=cut\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsysread%2Fpromises-channel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsysread%2Fpromises-channel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsysread%2Fpromises-channel/lists"}