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

Add Task support #12

Merged
merged 9 commits into from
Jan 1, 2018
Merged

Add Task support #12

merged 9 commits into from
Jan 1, 2018

Conversation

brendt
Copy link
Contributor

@brendt brendt commented Dec 25, 2017

A Task is another way of making a child process execute code, allowing for bootstrapping an application or parts of it. Eg. initialise the dependency container or load all config.

@brendt brendt requested a review from freekmurze December 25, 2017 11:47
@brendt
Copy link
Contributor Author

brendt commented Dec 31, 2017

@freekmurze Could you take a look at this one?

@freekmurze
Copy link
Member

freekmurze commented Dec 31, 2017 via email

Copy link
Member

@freekmurze freekmurze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool stuff!

README.md Outdated
@@ -29,7 +29,7 @@ foreach ($things as $thing) {
// Do a thing
})->then(function ($output) {
// Handle success
})->catch(function (Exception $e) {
})->catch(function (Throwable $e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very small nitpick: use $exception instead of $e

README.md Outdated
@@ -111,6 +111,34 @@ await($pool);
If an exception is thrown from within a child process, and not caught using the `->catch()` callback,
it will be thrown as `Spatie\Async\ParallelError` when calling `await()` or `$pool->wait()`.

### Working with tasks

Besides using closures, you can also work with a Task.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put Task in backticks

README.md Outdated
Besides using closures, you can also work with a Task.
A Task is useful in situations where you need more setup work in the child process.
Because a child process is always bootstrapped from nothing,
chances are you'll want to initialise eg. the dependency container before executing the task.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why start on a newline here? Could it be that you don't have line wrapping configured in your editor?

Copy link
Contributor Author

@brendt brendt Jan 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a habit I use for markdown files, because line wrapping in markdown files also enables it in PHP files, which I don't like. But I've added the changes.

abstract public function execute();

public function __invoke()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty cool way to make executing a task the same as executing a callable ❤️

README.md Outdated
}

// Add the task to the pool
$pool[] = async(new MyTask());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace that line by the more developer friendly:

$pool->add(new MyTask());

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

Successfully merging this pull request may close these issues.

2 participants