Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial implementation of processing #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

thekid
Copy link
Member

@thekid thekid commented May 1, 2016

A processing function can handle the processing of elements passed to it in the following ways:

  1. Do something with and pass it on down the chain, just like peek()
  2. Do something with and return a result, just like map()
  3. Decide not to pass it on, just like filter()
  4. Decide it cannot be handled now, and to retry it later (no equivalent)
  5. Defer its passing down the chain to a later point (no equivalent)

Example

Sequence::of($import)
  ->peek(function($record) { Console::write($record['name']); })
  ->process(function($processing, $record) {
    $existing= $this->database->lookup($record['name']);
    try {
      return $this->database->replace($existing, $record);
    } catch (InvalidRecord $e) {
      $processing->drop();
    } catch (DatabaseError $e) {
      $processing->retry($record, function() { sleep(5); });
    }
  }))
  ->peek(function($id) { Console::writeLine(' -> #', $id); )
  ->each()
;

thekid added 2 commits May 1, 2016 13:10
A processing function can handle the processing of elements passed to it
in the following ways:

1. Do something with and pass it on down the chain, just like peek()
2. Do something with and return a result, just like map()
3. Decide not to pass it on, just like filter()
4. Decide it cannot be handled now, and to retry it later (no equivalent)
5. Defer its passing down the chain to a later point (no equivalent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant