• Stars
    star
    1,461
  • Rank 30,854 (Top 0.7 %)
  • Language
    Elixir
  • Created over 7 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Computational parallel flows on top of GenStage

Flow Build Status

Flow allows developers to express computations on collections, similar to the Enum and Stream modules, although computations will be executed in parallel using multiple GenStages.

Here is a quick example on how to count words in a document in parallel with Flow:

File.stream!("path/to/some/file")
|> Flow.from_enumerable()
|> Flow.flat_map(&String.split(&1, " "))
|> Flow.partition()
|> Flow.reduce(fn -> %{} end, fn word, acc ->
  Map.update(acc, word, 1, & &1 + 1)
end)
|> Enum.to_list()

See documentation for Flow or JosΓ© Valim's keynote at ElixirConf 2016 introducing the main concepts behind GenStage and Flow.

Installation

Flow requires Elixir v1.7 and Erlang/OTP 22+. Add :flow to your list of dependencies in mix.exs:

def deps do
  [{:flow, "~> 1.0"}]
end

Usage in Livebook

Flow pipelines starts several processes linked to the current process. This means that, if there is an error in your Flow, it will shut down the Livebook runtime. You can avoid this in your notebooks in two different ways:

  1. Use Flow.stream(flow, link: false) to explicitly convert a Flow to a non-linked stream. You can them invoke Enum and Stream functions regularly:

    Flow.from_enumerable([1, 2, 3])
    |> Flow.map(& &1 * 2)
    |> Flow.stream(link: false)
    |> Enum.to_list()
  2. By trapping exits once before the Flow computation starts:

    Process.flag(:trap_exit, true)

License

Copyright 2017 Plataformatec
Copyright 2020 Dashbit

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

More Repositories

1

broadway

Concurrent and multi-stage data ingestion and data processing with Elixir
Elixir
2,278
star
2

mox

Mocks and explicit contracts in Elixir
Elixir
1,266
star
3

nimble_parsec

A simple and fast library for text-based parser combinators
Elixir
760
star
4

nimble_csv

A simple and fast CSV parsing and dumping library for Elixir
Elixir
732
star
5

nimble_options

A tiny library for validating and documenting high-level options. πŸ’½
Elixir
455
star
6

nimble_publisher

A minimal filesystem-based publishing engine with Markdown support and code highlighting
Elixir
419
star
7

nimble_totp

A tiny Elixir library for time-based one time passwords (TOTP)
Elixir
365
star
8

bytepack_archive

Archive of bytepack.io
Elixir
319
star
9

nimble_pool

A tiny resource-pool implementation for Elixir
Elixir
312
star
10

broadway_kafka

A Broadway connector for Kafka
Elixir
216
star
11

mix_phx_gen_auth_demo

Example repository for mix phx.gen.auth
Elixir
213
star
12

broadway_dashboard

Keep track of your Broadway pipelines from Phoenix LiveDashboard
Elixir
196
star
13

broadway_rabbitmq

A Broadway producer for RabbitMQ
Elixir
189
star
14

broadway_sqs

A Broadway producer for Amazon SQS
Elixir
91
star
15

broadway_cloud_pub_sub

A Broadway producer for Google Cloud Pub/Sub
Elixir
68
star
16

nimble_ownership

Elixir
48
star
17

broadway_bike_sharing_rabbitmq_example

An example of a Broadway pipeline for a bike sharing app with RabbitMQ and PostgreSQL
Elixir
47
star
18

nimble_strftime

A simple and fast strftime-based datetime formatter
Elixir
36
star
19

unpickler

A library for loading data in the Python's pickle format
Elixir
10
star
20

broadway_website

Landing page for the Elixir Broadway library.
HTML
6
star