Coder Social home page Coder Social logo

datapipes's Introduction

datapipes Build Status Gem Version

datapipes is an asynchronous multi streaming library.

Coverage Status Code Climate Dependency Status

About

datapipes encourages to handle multi streamings asynchronously. datapipes has a few objects sparated by its responsibility.

  • Source Produces resources and emits the resource to pipe.
  • Tube Effector for resources. Processes resource in the middle of pipe.
  • Sink Consumer for resources. Do something with processed resources.
  • Pipe Resources pass through the pipe. Handles resources asynchronously.
 Source
   |   โ†“ data flow
   |
  Tube
   |    pipe is '|'
   |
  Sink

To handle multi streamings, datapipes offers composabiliy. Source, Tube and Sink are composable individually. So the diagram above will be:

 Composed Source works concurrently.

  [Source Source Source]
            |
            |  pipe handles asynchronous.
            |
           Tube
           Tube  Composed Tube has individual tube in series.
           Tube
           Tube
            |
            |
            |
     [Sink Sink Sink]

 Composed Sink works concurrently.

Installation

Add this line to your application's Gemfile:

gem 'datapipes'

And then execute:

$ bundle

Or install it yourself as:

$ gem install datapipes

Usage

You have to define your own Source, Tube and Sink.

A basic source is list type. it produces a value in several times. Use produce method to emit data to pipe.

class List < Datapipes::Source
  def run
    (1..10).each {|i| produce(i) }
  end
end

Next is tube. Tube processes piped data. A example tube recieve Integer value then increase amount of the value.

Define accept? to recieve the data or skip this.

class Triple < Datapipes::Tube
  def run(data)
    if accept? data
      [data, data, data]
    else
      data
    end
  end

  def accept?(data)
    data.is_a? Integer and data > 3
  end
end

Sink consumes piped data. A typical sink is printing data.

class Print < Datapipes::Sink
  def run(data)
    puts data if accept? data
  end

  def accept?(data)
    data.is_a? Array and data[0] < 7
  end
end

You can make your own datapipe with your objects.

datapipe = Datapipes.new(
  List.new,        # A source
  Print.new,       # A sink
  tube: Triple.new,
)

Then just run everything with run_resource.

datapipe.run_resource

The output will be:

4
4
4
5
5
5
6
6
6

Congratulation!!

Composing objects

TODO...

Contributing

  1. Fork it ( http://github.com/taiki45/datapipes/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

datapipes's People

Contributors

taiki45 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.