Scope.map
Behavior: Async map.
Source and package
- Qualified name
-
LibTmux:: Async:: Scope# map - Module
- LibTmux::Async
- Declared in
Scope- Package
- libtmux-async
- Source
- gems/libtmux-async/lib/libtmux/async/scope.rb
-
Description#
Behavior contract: Async map.
Examples#
Open an Async scope over an existing server and capture every pane concurrently, in input order. Use Ruby 3.3 or newer with Bundler, and tmux 3.3a or newer, on Unix with
/bin/catand/bin/shavailable. In an empty directory, save thisGemfile:source "https://rubygems.org"gem "libtmux-async", "0.1.1"Save this complete program as
async_scope.rb. ItsServer.start()block owns a private tmux server and stops it on exit, including after an error. View source# frozen_string_literal: truebegin# docs:begin mainrequire "libtmux"require "libtmux/async"LibTmux::Server.start do |server|server.new_session(name: "work", command: ["/bin/cat"])server.new_session(name: "logs", command: ["/bin/cat"])Async do |parent|LibTmux::Async.open(parent: parent, server: server) do |scope|refs = scope.server.list_panes.map(&:ref)screens = scope.map(refs, concurrency: 2) { |ref| scope.server.pane(ref).capture }puts "captured panes: #{screens.length}"puts "all succeeded: #{screens.all?(&:success?)}"endend.waitend# docs:end mainrescue StandardError => errorwarn "#{error.class}: #{error.message}"exit 1endInstall the gem and run the program. An operation or cleanup error makes it exit unsuccessfully:
Terminal window $ bundle install && \bundle exec ruby async_scope.rbExpected output:
captured panes: 2all succeeded: true
Guides#
Pages that discuss map.