Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevanzuydam committed Sep 4, 2023
2 parents 4412bed + 0df9c42 commit b9c492f
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/templates/documentation/advanced/threads.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% set title = 'Threads' %}

{% set introduction %}
If services do not meet the required use case, perhaps one wants a more immediate action, or the server environment
does not allow command line interaction, threads could be an option.
{% endset %}

{% set requirements = ['Threads', 'Routing'] %}

{% set content %}
<h5>Registering a thread</h5>
<p>Adding a trigger to start a thread, can be done anywhere in the code. Just remember that it has to have run before
actually calling the trigger. If the use case is just to start a thread, then the trigger registration and trigger call
can happen in the same place. If the trigger needs to be used in multiple places, probably best to place it somewhere
that the composer autoload will find it. Suggestion is to create a triggers.php file in the "src/app"
<pre><code>{{ include_code("examples/advanced-threads-register.twig"| raw) }}</code></pre>
</p>

<h5>Firing off a thread</h5>
<p>A simple line of code fires off the thread. It uses the trigger name, and an array of parameters. The order of the
parameters, matches the order of arguments in the trigger function.
<pre><code>{{ include_code("examples/advanced-threads-fire.twig"| raw) }}</code></pre>
</p>

<h5>Debugging threads</h5>
<p>The getEvents() method in the Thread class can be used to see what handlers (registered Threads) and events
(Thread calls) exists upto the point of calling the method.
<pre><code>{{ include_code("examples/advanced-threads-get.twig"| raw) }}</code></pre>
</p>
{% endset %}

{% set tips = [
'The thread code is not allowed to have comments and can only have simple variables',
'To register a thread you can use onTrigger or addTrigger'
]
%}

{% include "documentation/components/help-segment.twig" %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
\Tina4\Get::add("/test-trigger", function (\Tina4\Response $response) {

\Tina4\Thread::trigger("register-me", ["Tina", "Good morning"]);

return $response("This will add to the file: 'Good morning, Tina'");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$debugThreads = \Tina4\Thread::getEvents()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
\Tina4\Thread::onTrigger("register-me", static function ($name, $greeting) {
file_put_contents("trigger.txt", "{$greeting}, {$name}", FILE_APPEND);
});
2 changes: 2 additions & 0 deletions src/templates/documentation/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<div class="accordion-body">
<p><a href="#advanced-modules">Modules</a></p>
<p><a href="#advanced-services">Services</a></p>
<p><a href="#advanced-threads">Threads</a></p>
</div>
</div>
</div>
Expand Down Expand Up @@ -264,6 +265,7 @@
<h2>Advanced</h2>
{% include "documentation/advanced/modules.twig" with { anchor: 'advanced-modules' } %}
{% include "documentation/advanced/services.twig" with { anchor: 'advanced-services' } %}
{% include "documentation/advanced/threads.twig" with { anchor: 'advanced-threads' } %}
<h2>Contributing</h2>
<a href="https://loom.com/invite/6a3f0227ce5e4123909a853d07d35612">Making videos on Loom</a>
<h2>Setup Environment</h2>
Expand Down

0 comments on commit b9c492f

Please sign in to comment.