Files
swift-service-lifecycle/docs/current/Lifecycle/Classes/ComponentLifecycle.html
T

691 lines
35 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="en">
<head>
<title>ComponentLifecycle Class Reference</title>
<link rel="stylesheet" type="text/css" href="../css/jazzy.css" />
<link rel="stylesheet" type="text/css" href="../css/highlight.css" />
<meta charset="utf-8">
<script src="../js/jquery.min.js" defer></script>
<script src="../js/jazzy.js" defer></script>
<script src="../js/lunr.min.js" defer></script>
<script src="../js/typeahead.jquery.js" defer></script>
<script src="../js/jazzy.search.js" defer></script>
</head>
<body>
<a name="//apple_ref/swift/Class/ComponentLifecycle" class="dashAnchor"></a>
<a title="ComponentLifecycle Class Reference"></a>
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Lifecycle 1.0.0-alpha.4 Docs
</a>
(76% documented)
</p>
<p class="header-col--secondary">
<form role="search" action="../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
</form>
</p>
<p class="header-col header-col--secondary">
<a class="header-link" href="https://github.com/swift-server/swift-service-lifecycle">
<img class="header-icon" src="../img/gh.png"/>
View on GitHub
</a>
</p>
<p class="header-col header-col--secondary">
<a class="header-link" href="dash-feed://https%3A%2F%2Fswift-server.github.io%2Fswift-service-lifecycle%2Fdocs%2F1.0.0-alpha.4%2FLifecycle%2Fdocsets%2FLifecycle.xml">
<img class="header-icon" src="../img/dash.png"/>
Install in Dash
</a>
</p>
</header>
<p class="breadcrumbs">
<a class="breadcrumb" href="../index.html">Lifecycle Reference</a>
<img class="carat" src="../img/carat.png" />
ComponentLifecycle Class Reference
</p>
<div class="content-wrapper">
<nav class="navigation">
<ul class="nav-groups">
<li class="nav-group-name">
<a class="nav-group-name-link" href="../Classes.html">Classes</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="../Classes/ComponentLifecycle.html">ComponentLifecycle</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="../Protocols.html">Protocols</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="../Protocols/LifecycleTask.html">LifecycleTask</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="../Structs.html">Structures</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="../Structs/LifecycleHandler.html">LifecycleHandler</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="../Structs/ServiceLifecycle.html">ServiceLifecycle</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="../Structs/ServiceLifecycle/Signal.html">– Signal</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="../Structs/ServiceLifecycle/Configuration.html">– Configuration</a>
</li>
</ul>
</li>
</ul>
</nav>
<article class="main-content">
<section class="section">
<div class="section-content top-matter">
<h1>ComponentLifecycle</h1>
<div class="declaration">
<div class="language">
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">ComponentLifecycle</span> <span class="p">:</span> <span class="kt"><a href="../Protocols/LifecycleTask.html">LifecycleTask</a></span></code></pre>
</div>
</div>
<p><code>Lifecycle</code> provides a basic mechanism to cleanly startup and shutdown the application, freeing resources in order before exiting.</p>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.4/Sources/Lifecycle/Lifecycle.swift#L254-L464">Show on GitHub</a>
</div>
</div>
</section>
<section class="section">
<div class="section-content">
<div class="task-group">
<ul class="item-container">
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle09ComponentA0C5labelSSvp"></a>
<a name="//apple_ref/swift/Property/label" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle09ComponentA0C5labelSSvp">label</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Undocumented</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="k">let</span> <span class="nv">label</span><span class="p">:</span> <span class="kt">String</span></code></pre>
</div>
</div>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.4/Sources/Lifecycle/Lifecycle.swift#L">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle09ComponentA0C5label6loggerACSS_7Logging6LoggerVSgtcfc"></a>
<a name="//apple_ref/swift/Method/init(label:logger:)" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle09ComponentA0C5label6loggerACSS_7Logging6LoggerVSgtcfc">init(label:<wbr>logger:<wbr>)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Creates a <code>ComponentLifecycle</code> instance.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="nf">init</span><span class="p">(</span><span class="nv">label</span><span class="p">:</span> <span class="kt">String</span><span class="p">,</span> <span class="nv">logger</span><span class="p">:</span> <span class="kt">Logger</span><span class="p">?</span> <span class="o">=</span> <span class="kc">nil</span><span class="p">)</span></code></pre>
</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>label</em>
</code>
</td>
<td>
<div>
<p>label of the item, useful for debugging.</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>logger</em>
</code>
</td>
<td>
<div>
<p><code>Logger</code> to log with.</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.4/Sources/Lifecycle/Lifecycle.swift#L270-L274">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle09ComponentA0C5startyyys5Error_pSgcF"></a>
<a name="//apple_ref/swift/Method/start(_:)" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle09ComponentA0C5startyyys5Error_pSgcF">start(_:<wbr>)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Starts the provided <code>LifecycleItem</code> array.
Startup is performed in the order of items provided.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">start</span><span class="p">(</span><span class="n">_</span> <span class="nv">callback</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt">Error</span><span class="p">?)</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span></code></pre>
</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>callback</em>
</code>
</td>
<td>
<div>
<p>The handler which is called after the start operation completes. The parameter will be <code>nil</code> on success and contain the <code>Error</code> otherwise.</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.4/Sources/Lifecycle/Lifecycle.swift#L281-L283">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle09ComponentA0C5start2on_y8Dispatch0E5QueueC_ys5Error_pSgctF"></a>
<a name="//apple_ref/swift/Method/start(on:_:)" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle09ComponentA0C5start2on_y8Dispatch0E5QueueC_ys5Error_pSgctF">start(on:<wbr>_:<wbr>)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Starts the provided <code>LifecycleItem</code> array.
Startup is performed in the order of items provided.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">start</span><span class="p">(</span><span class="n">on</span> <span class="nv">queue</span><span class="p">:</span> <span class="kt">DispatchQueue</span><span class="p">,</span> <span class="n">_</span> <span class="nv">callback</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt">Error</span><span class="p">?)</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span></code></pre>
</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>on</em>
</code>
</td>
<td>
<div>
<p><code>DispatchQueue</code> to run the handlers callback on</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>callback</em>
</code>
</td>
<td>
<div>
<p>The handler which is called after the start operation completes. The parameter will be <code>nil</code> on success and contain the <code>Error</code> otherwise.</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.4/Sources/Lifecycle/Lifecycle.swift#L291-L294">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle09ComponentA0C12startAndWait2ony8Dispatch0G5QueueC_tKF"></a>
<a name="//apple_ref/swift/Method/startAndWait(on:)" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle09ComponentA0C12startAndWait2ony8Dispatch0G5QueueC_tKF">startAndWait(on:<wbr>)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Starts the provided <code>LifecycleItem</code> array and waits (blocking) until <code>shutdown</code> is called on another thread.
Startup is performed in the order of items provided.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">startAndWait</span><span class="p">(</span><span class="n">on</span> <span class="nv">queue</span><span class="p">:</span> <span class="kt">DispatchQueue</span> <span class="o">=</span> <span class="o">.</span><span class="nf">global</span><span class="p">())</span> <span class="k">throws</span></code></pre>
</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>on</em>
</code>
</td>
<td>
<div>
<p><code>DispatchQueue</code> to run the handlers callback on</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.4/Sources/Lifecycle/Lifecycle.swift#L301-L312">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle09ComponentA0C8shutdownyyys5Error_pSgcF"></a>
<a name="//apple_ref/swift/Method/shutdown(_:)" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle09ComponentA0C8shutdownyyys5Error_pSgcF">shutdown(_:<wbr>)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Shuts down the <code>LifecycleItem</code> array provided in <code>start</code> or <code>startAndWait</code>.
Shutdown is performed in reverse order of items provided.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">shutdown</span><span class="p">(</span><span class="n">_</span> <span class="nv">callback</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt">Error</span><span class="p">?)</span> <span class="o">-&gt;</span> <span class="kt">Void</span> <span class="o">=</span> <span class="p">{</span> <span class="n">_</span> <span class="k">in</span> <span class="p">})</span></code></pre>
</div>
</div>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.4/Sources/Lifecycle/Lifecycle.swift#L316-L350">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle09ComponentA0C4waityyF"></a>
<a name="//apple_ref/swift/Method/wait()" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle09ComponentA0C4waityyF">wait()</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Waits (blocking) until <code>shutdown</code> is invoked on another thread.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">wait</span><span class="p">()</span></code></pre>
</div>
</div>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.4/Sources/Lifecycle/Lifecycle.swift#L353-L355">Show on GitHub</a>
</div>
</section>
</div>
</li>
</ul>
</div>
<div class="task-group">
<div class="task-name-container">
<a name="/ComponentLifecycle"></a>
<a name="//apple_ref/swift/Section/ComponentLifecycle" class="dashAnchor"></a>
<div class="section-name-container">
<a class="section-name-link" href="#/ComponentLifecycle"></a>
<h3 class="section-name"><p>ComponentLifecycle</p>
</h3>
</div>
</div>
<ul class="item-container">
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle09ComponentA0C8registeryyAA0A4Task_pd_tF"></a>
<a name="//apple_ref/swift/Method/register(_:)" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle09ComponentA0C8registeryyAA0A4Task_pd_tF">register(_:<wbr>)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Adds a <code>Task</code> to a <code>Tasks</code> collection.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">func</span> <span class="nf">register</span><span class="p">(</span><span class="n">_</span> <span class="nv">tasks</span><span class="p">:</span> <span class="kt"><a href="../Protocols/LifecycleTask.html">LifecycleTask</a></span><span class="o">...</span><span class="p">)</span></code></pre>
</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>tasks</em>
</code>
</td>
<td>
<div>
<p>one or more <code>Tasks</code>.</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.4/Sources/Lifecycle/Lifecycle.swift#L485-L487">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle09ComponentA0C8registeryySayAA0A4Task_pGF"></a>
<a name="//apple_ref/swift/Method/register(_:)" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle09ComponentA0C8registeryySayAA0A4Task_pGF">register(_:<wbr>)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Adds a <code>Task</code> to a <code>Tasks</code> collection.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">func</span> <span class="nf">register</span><span class="p">(</span><span class="n">_</span> <span class="nv">tasks</span><span class="p">:</span> <span class="p">[</span><span class="kt"><a href="../Protocols/LifecycleTask.html">LifecycleTask</a></span><span class="p">])</span></code></pre>
</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>tasks</em>
</code>
</td>
<td>
<div>
<p>array of <code>Tasks</code>.</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.4/Sources/Lifecycle/Lifecycle.swift#L493-L502">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle09ComponentA0C8register5label5start8shutdownySS_AA0A7HandlerVAItF"></a>
<a name="//apple_ref/swift/Method/register(label:start:shutdown:)" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle09ComponentA0C8register5label5start8shutdownySS_AA0A7HandlerVAItF">register(label:<wbr>start:<wbr>shutdown:<wbr>)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Adds a <code>Task</code> to a <code>Tasks</code> collection.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">func</span> <span class="nf">register</span><span class="p">(</span><span class="nv">label</span><span class="p">:</span> <span class="kt">String</span><span class="p">,</span> <span class="nv">start</span><span class="p">:</span> <span class="kt"><a href="../Structs/LifecycleHandler.html">LifecycleHandler</a></span><span class="p">,</span> <span class="nv">shutdown</span><span class="p">:</span> <span class="kt"><a href="../Structs/LifecycleHandler.html">LifecycleHandler</a></span><span class="p">)</span></code></pre>
</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>label</em>
</code>
</td>
<td>
<div>
<p>label of the item, useful for debugging.</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>start</em>
</code>
</td>
<td>
<div>
<p><code>Handler</code> to perform the startup.</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>shutdown</em>
</code>
</td>
<td>
<div>
<p><code>Handler</code> to perform the shutdown.</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.4/Sources/Lifecycle/Lifecycle.swift#L510-L512">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle09ComponentA0C16registerShutdown5label_ySS_AA0A7HandlerVtF"></a>
<a name="//apple_ref/swift/Method/registerShutdown(label:_:)" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle09ComponentA0C16registerShutdown5label_ySS_AA0A7HandlerVtF">registerShutdown(label:<wbr>_:<wbr>)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Adds a <code>Task</code> to a <code>Tasks</code> collection.</p>
</div>
<div class="declaration">
<h4>Declaration</h4>
<div class="language">
<p class="aside-title">Swift</p>
<pre class="highlight swift"><code><span class="kd">func</span> <span class="nf">registerShutdown</span><span class="p">(</span><span class="nv">label</span><span class="p">:</span> <span class="kt">String</span><span class="p">,</span> <span class="n">_</span> <span class="nv">handler</span><span class="p">:</span> <span class="kt"><a href="../Structs/LifecycleHandler.html">LifecycleHandler</a></span><span class="p">)</span></code></pre>
</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>label</em>
</code>
</td>
<td>
<div>
<p>label of the item, useful for debugging.</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>handler</em>
</code>
</td>
<td>
<div>
<p><code>Handler</code> to perform the shutdown.</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.4/Sources/Lifecycle/Lifecycle.swift#L519-L521">Show on GitHub</a>
</div>
</section>
</div>
</li>
</ul>
</div>
</div>
</section>
</article>
</div>
<section class="footer">
<p>&copy; 2020 <a class="link" href="https://github.com/swift-server/swift-service-lifecycle" target="_blank" rel="external">SwiftServiceLifecycle team</a>. All rights reserved. (Last updated: 2020-07-15)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.5</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
</div>
</html>