Sha256: fe2fb2114a61344736f1d7e38ed456331d82237ec5e168eac35f928e44cd7bed

Contents?: true

Size: 1.79 KB

Versions: 1

Compression:

Stored size: 1.79 KB

Contents

# depth_first
Depth-first search code organization gem allowing for sequential and concurrent code execution using [concurrent-ruby](https://github.com/ruby-concurrency/concurrent-ruby).

## Tasks
A task accepts an input hash and merges in a results hash.

### Examples
```
class A < DepthFirst::Task
  def perform
    { a: 1 }
  end
end

class B < DepthFirst::Task
  def perform
    { b: 2 }
  end
end

class C < DepthFirst::Task
  def perform
    { c: 3 }
  end
end
```

### Usage
```
> A.new(test: true).perform
 => { test: true, a: 1 }

> B.new(test: true).perform
 => { test: true, b: 2 }
```

## Organizers
An organizer chains together tasks, piping a hash through each subtask.

## SequentialOrganizer
Data is passed through `A`, `B`, and `C` sequentially. The input hash `{ testing: true }` is piped through A. The resulting hash `{ testing: true, a: 1 }` is then piped through B. And so on.

### Example
```
class SequentialAbc < DepthFirst::SequentialOrganizer
  TASKS = [A, B, C].freeze
end
```

### Usage
```
> SequentialAbc.new(testing: true).perform
 => { testing: true, a: 1, b: 2, c: 3 }
```

## ParallelOrganizer
Data is passed through `A`, `B`, and `C` concurrently. All three classes execute in parallel. The input hash `{ testing: true }` is passed to all three classes and all three intermediate result hashes are merged into the final result hash once their promises are resolved.

### Example
```
class ParallelAbc < DepthFirst::ParallelOrganizer
  TASKS = [A, B, C].freeze
end
```

### Usage
```
> ParallelAbc.new(testing: true).perform
 => { testing: true, a: 1, b: 2, c: 3}
```

## Note
An organizer can have a subtask which is itself another organizer. In this manner, code can be organized in an arbitrarily-deep tree structure with order of execution roughly matching a Depth First Search algorithm.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
depth_first-1.1.0 README.md