txt: ## supply.md
  ## Chunk 2 of 2
   than any value seen before. In other words, from a continuously ascending supply it will emit all the values. From a continuously descending supply it will only emit the first value. The optional parameter specifies the comparator, just as with [Any.max](/type/Any#routine_max).
  
  ## [method min](#class_Supply "go to top of document")[§](#method_min "direct link")
  
  ```raku
  method min(Supply:D: &custom-routine-to-use = &infix:<cmp> --> Supply:D)
  ```
  
  Creates a supply that only emits values from the given supply if they are smaller than any value seen before. In other words, from a continuously descending supply it will emit all the values. From a continuously ascending supply it will only emit the first value. The optional parameter specifies the comparator, just as with [Any.min](/type/Any#routine_min).
  
  ## [method minmax](#class_Supply "go to top of document")[§](#method_minmax "direct link")
  
  ```raku
  method minmax(Supply:D: &custom-routine-to-use = &infix:<cmp> --> Supply:D)
  ```
  
  Creates a supply that emits a Range every time a new minimum or maximum values is seen from the given supply. The optional parameter specifies the comparator, just as with [Any.minmax](/type/Any#routine_minmax).
  
  ## [method skip](#class_Supply "go to top of document")[§](#method_skip "direct link")
  
  ```raku
  method skip(Supply:D: Int(Cool) $number = 1 --> Supply:D)
  ```
  
  Returns a new `Supply` which will emit all values from the given `Supply` except for the first `$number` values, which will be thrown away.
  
  ```raku
  my $supplier = Supplier.new;
  my $supply = $supplier.Supply;
  $supply = $supply.skip(3);
  $supply.tap({ say $_ });
  $supplier.emit($_) for 1..10; # OUTPUT: «4␤5␤6␤7␤8␤9␤10␤»
  
  ```
  
  ## [method start](#class_Supply "go to top of document")[§](#method_start "direct link")
  
  ```raku
  method start(Supply:D: &startee --> Supply:D)
  ```
  
  Creates a supply of supplies. For each value in the original supply, the code object is scheduled on another thread, and returns a supply either of a single value (if the code succeeds), or one that quits without a value (if the code fails).
  
  This is useful for asynchronously starting work that you don't block on.
  
  Use `migrate` to join the values into a single supply again.
  
  ## [method migrate](#class_Supply "go to top of document")[§](#method_migrate "direct link")
  
  ```raku
  method migrate(Supply:D: --> Supply:D)
  ```
  
  Takes a `Supply` which itself has values that are of type `Supply` as input. Each time the outer `Supply` emits a new `Supply`, this will be tapped and its values emitted. Any previously tapped `Supply` will be closed. This is useful for migrating between different data sources, and only paying attention to the latest one.
  
  For example, imagine an application where the user can switch between different stocks. When they switch to a new one, a connection is established to a web socket to get the latest values, and any previous connection should be closed. Each stream of values coming over the web socket would be represented as a Supply, which themselves are emitted into a Supply of latest data sources to watch. The `migrate` method could be used to flatten this supply of supplies into a single Supply of the current values that the user cares about.
  
  Here is a simple simulation of such a program:
  
  ```raku
  my Supplier $stock-sources .= new;
  
  sub watch-stock($symbol) {
      $stock-sources.emit: supply {
          say "Starting to watch $symbol";
          whenever Supply.interval(1) {
              emit "$symbol: 111." ~ 99.rand.Int;
          }
          CLOSE say "Lost interest in $symbol";
      }
  }
  
  $stock-sources.Supply.migrate.tap: *.say;
  
  watch-stock('GOOG');
  sleep 3;
  watch-stock('AAPL');
  sleep 3;
  
  ```
  
  Which produces output like:
  
  ｢text｣ without highlighting
  
  ```
  
  
  ```
  
  Starting to watch GOOG
  GOOG: 111.67
  GOOG: 111.20
  GOOG: 111.37
  Lost interest in GOOG
  Starting to watch AAPL
  AAPL: 111.55
  AAPL: 111.6
  AAPL: 111.6
  
  
  ```
  
  
  ```
  
  # [Methods that combine supplies](#class_Supply "go to top of document")[§](#Methods_that_combine_supplies "direct link")
  
  ## [method merge](#class_Supply "go to top of document")[§](#method_merge "direct link")
  
  ```raku
  method merge(Supply @*supplies --> Supply:D)
  ```
  
  Creates a supply to which any value seen from the given supplies, is emitted. The resulting supply is done only when all given supplies are done. Can also be called as a class method.
  
  ## [method zip](#class_Supply "go to top of document")[§](#method_zip "direct link")
  
  ```raku
  method zip(**@s, :&with)
  ```
  
  Creates a supply that emits combined values as soon as there is a new value seen on **all** of the supplies. By default, [`List`](/type/List)s are created, but this can be changed by specifying your own combiner with the `:with` parameter. The resulting supply is done as soon as **any** of the given supplies are done. Can also be called as a class method.
  
  This can also be used as a class method; in case it's used as an object method the corresponding supply will be one of the supplies combined (with no special treatment).
  
  ## [method zip-latest](#class_Supply "go to top of document")[§](#method_zip-latest "direct link")
  
  ```raku
  method zip-latest(**@s, :&with, :$initial )
  ```
  
  Creates a supply that emits combined values as soon as there is a new value seen on **any** of the supplies. By default, [`List`](/type/List)s are created, but this can be changed by specifying your own combiner with the `:with` parameter. The optional :initial parameter can be used to indicate the initial state of the combined values. By default, all supplies have to have at least one value emitted on them before the first combined values is emitted on the resulting supply. The resulting supply is done as soon as **any** of the given supplies are done. Can also be called as a class method.
  
  # [I/O features exposed as supplies](#class_Supply "go to top of document")[§](#I/O_features_exposed_as_supplies "direct link")
  
  ## [sub signal](#class_Supply "go to top of document")[§](#sub_signal "direct link")
  
  ```raku
  sub signal(*@signals, :$scheduler = $*SCHEDULER)
  ```
  
  Creates a supply for the Signal enums (such as SIGINT) specified, and an optional `:scheduler` parameter. Any signals received, will be emitted on the supply. For example:
  
  ```raku
  signal(SIGINT).tap( { say "Thank you for your attention"; exit 0 } );
  ```
  
  would catch Control-C, thank you, and then exit.
  
  To go from a signal number to a Signal, you can do something like this:
  
  ```raku
  signal(Signal(2)).tap( -> $sig { say "Received signal: $sig" } );
  ```
  
  The list of supported signals can be found by checking `Signal::.keys` (as you would any enum). For more details on how enums work see [enum](/language/typesystem#enum).
  
  **Note:** [Rakudo](/language/glossary#Rakudo) versions up to 2018.05 had a bug due to which numeric values of signals were incorrect on some systems. For example, `Signal(10)` was returning `SIGBUS` even if it was actually `SIGUSR1` on a particular system. That being said, using `signal(SIGUSR1)` was working as expected on all Rakudo versions except 2018.04, 2018.04.1 and 2018.05, where the intended behavior can be achieved by using `signal(SIGBUS)` instead. These issues are resolved in Rakudo releases after 2018.05.
  
  ## [method IO::Notification.watch-path](#class_Supply "go to top of document")[§](#method_IO::Notification.watch-path "direct link")
  
  ```raku
  method watch-path($path --> Supply:D)
  
  ```
  
  Creates a supply to which the OS will emit values to indicate changes on the filesystem for the given path. Also has a shortcut with the `watch` method on an IO object, like this:
  
  ```raku
  IO::Notification.watch-path(".").act( { say "$^file changed" } );
  ".".IO.watch.act(                     { say "$^file changed" } );   # same
  
  ```
  
  # [Typegraph](# "go to top of document")[§](#typegraphrelations "direct link")
  
  Type relations for `Supply`
  
  
  
  raku-type-graph
  
  
  
  Supply
  Supply
  
  
  Any
  Any
  
  
  Supply->Any
  
  
  
  Mu
  Mu
  
  
  Any->Mu
  
  [Expand chart above](/assets/typegraphs/Supply.svg)
  