-
-
Notifications
You must be signed in to change notification settings - Fork 179
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
Add Task support #12
Conversation
Apply fixes from StyleCI
Apply fixes from StyleCI
@freekmurze Could you take a look at this one? |
Sure! 👍
On Sun, 31 Dec 2017 at 10:08, Brent Roose ***@***.***> wrote:
@freekmurze <https://github.com/freekmurze> Could you take a look at this
one?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAdiDVBOQvEnoC_wUk-gaLCYC0c7EqYsks5tF08EgaJpZM4RMQ60>
.
--
Freek Van der Herten https://spatie.be +32 495 84 27 91
|
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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());
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.