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

Parallelization #4

Open
thekid opened this issue Nov 17, 2014 · 1 comment
Open

Parallelization #4

thekid opened this issue Nov 17, 2014 · 1 comment

Comments

@thekid
Copy link
Member

thekid commented Nov 17, 2014

Given a sequence of elements I would like to be able to spawn workers and relay work to them.

$thumbs= new Folder('thumbs');
Sequence::of(new IOCollectionIterator('.', true))
  ->filter(new ExtensionEqualsFilter('.jpg'))
  ->each(function($e) use($thumbs) {
    $image= Image::loadFrom(new JpegStreamReader($e->getInputStream()));
    $thumb= Image::create(400, 300);
    $thumb->resampleFrom($image);
    $thumb->saveTo(new JpegStreamWriter((new File($thumbs, $e->getName())->out());
  }))
;
@thekid
Copy link
Member Author

thekid commented Nov 17, 2014

$worker= function() {
  return Runtime::getInstance()->newInstance(
    null,
    'class',
    'com.example.ResampleTo',
    ['--files-from=-', $thumbs->getUri()]
  );
};

Sequence::of(new IOCollectionIterator('.', true))
  ->filter(new ExtensionEqualsFilter('.jpg'))
  ->distribute(new Evenly(4), $worker, function($process, $e) {
    $process->in->write($e->getUri());
   })
  ->wait()
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant