Files

545 lines
29 KiB
HTML
Raw Permalink 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>ServiceLifecycle Structure 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/Struct/ServiceLifecycle" class="dashAnchor"></a>
<a title="ServiceLifecycle Structure Reference"></a>
<header class="header">
<p class="header-col header-col--primary">
<a class="header-link" href="../index.html">
Lifecycle 1.0.0-alpha.10 Docs
</a>
(79% documented)
</p>
<div class="header-col--secondary">
<form role="search" action="../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
</form>
</div>
<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" alt="GitHub"/>
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.10%2FLifecycle%2Fdocsets%2FLifecycle.xml">
<img class="header-icon" src="../img/dash.png" alt="Dash"/>
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" alt=""/>
ServiceLifecycle Structure 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>
<li class="nav-group-task">
<a class="nav-group-task-link" href="../Protocols/LifecycleTasksContainer.html">LifecycleTasksContainer</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/LifecycleShutdownHandler.html">LifecycleShutdownHandler</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="../Structs/LifecycleStartHandler.html">LifecycleStartHandler</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>ServiceLifecycle</h1>
<div class="declaration">
<div class="language">
<pre class="highlight swift"><code><span class="kd">public</span> <span class="kd">struct</span> <span class="kt">ServiceLifecycle</span></code></pre>
<pre class="highlight swift"><code><span class="kd">extension</span> <span class="kt">ServiceLifecycle</span><span class="p">:</span> <span class="kt"><a href="../Protocols/LifecycleTasksContainer.html">LifecycleTasksContainer</a></span></code></pre>
</div>
</div>
<p><code>ServiceLifecycle</code> provides a basic mechanism to cleanly startup and shutdown the application, freeing resources in order before exiting.
By default, also install shutdown hooks based on <code>Signal</code> and backtraces.</p>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.10/Sources/Lifecycle/Lifecycle.swift#L250-L329">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:9Lifecycle07ServiceA0V13configurationA2C13ConfigurationV_tcfc"></a>
<a name="//apple_ref/swift/Method/init(configuration:)" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle07ServiceA0V13configurationA2C13ConfigurationV_tcfc">init(configuration:<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>ServiceLifecycle</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">configuration</span><span class="p">:</span> <span class="kt"><a href="../Structs/ServiceLifecycle/Configuration.html">Configuration</a></span> <span class="o">=</span> <span class="o">.</span><span class="nf">init</span><span class="p">())</span></code></pre>
</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>configuration</em>
</code>
</td>
<td>
<div>
<p>Defines lifecycle <code><a href="../Structs/ServiceLifecycle/Configuration.html">Configuration</a></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.10/Sources/Lifecycle/Lifecycle.swift#L262-L267">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle07ServiceA0V5startyyys5Error_pSgcF"></a>
<a name="//apple_ref/swift/Method/start(_:)" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle07ServiceA0V5startyyys5Error_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><a href="../Protocols/LifecycleTask.html">LifecycleTask</a></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.10/Sources/Lifecycle/Lifecycle.swift#L274-L280">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle07ServiceA0V12startAndWaityyKF"></a>
<a name="//apple_ref/swift/Method/startAndWait()" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle07ServiceA0V12startAndWaityyKF">startAndWait()</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><a href="../Protocols/LifecycleTask.html">LifecycleTask</a></code> array and waits (blocking) until a shutdown <code><a href="../Structs/ServiceLifecycle/Signal.html">Signal</a></code> is captured or <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="k">throws</span></code></pre>
</div>
</div>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.10/Sources/Lifecycle/Lifecycle.swift#L284-L290">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle07ServiceA0V8shutdownyyys5Error_pSgcF"></a>
<a name="//apple_ref/swift/Method/shutdown(_:)" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle07ServiceA0V8shutdownyyys5Error_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><a href="../Protocols/LifecycleTask.html">LifecycleTask</a></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>
<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.10/Sources/Lifecycle/Lifecycle.swift#L297-L299">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle07ServiceA0V4waityyF"></a>
<a name="//apple_ref/swift/Method/wait()" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle07ServiceA0V4waityyF">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 shutdown <code><a href="../Structs/ServiceLifecycle/Signal.html">Signal</a></code> is captured or <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.10/Sources/Lifecycle/Lifecycle.swift#L302-L304">Show on GitHub</a>
</div>
</section>
</div>
</li>
</ul>
</div>
<div class="task-group">
<div class="task-name-container">
<a name="/ServiceLifecycle"></a>
<a name="//apple_ref/swift/Section/ServiceLifecycle" class="dashAnchor"></a>
<div class="section-name-container">
<a class="section-name-link" href="#/ServiceLifecycle"></a>
<h3 class="section-name"><span>ServiceLifecycle</span>
</h3>
</div>
</div>
<ul class="item-container">
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle07ServiceA0V4trap6signal7handler2on15cancelAfterTrap8Dispatch0J12SourceSignal_pAC0L0V_yALcAI0J5QueueCSbtFZ"></a>
<a name="//apple_ref/swift/Method/trap(signal:handler:on:cancelAfterTrap:)" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle07ServiceA0V4trap6signal7handler2on15cancelAfterTrap8Dispatch0J12SourceSignal_pAC0L0V_yALcAI0J5QueueCSbtFZ">trap(signal:<wbr>handler:<wbr>on:<wbr>cancelAfterTrap:<wbr>)</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>Setup a signal trap.</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">static</span> <span class="kd">func</span> <span class="nf">trap</span><span class="p">(</span><span class="n">signal</span> <span class="nv">sig</span><span class="p">:</span> <span class="kt"><a href="../Structs/ServiceLifecycle/Signal.html">Signal</a></span><span class="p">,</span> <span class="nv">handler</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">(</span><span class="kt"><a href="../Structs/ServiceLifecycle/Signal.html">Signal</a></span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">Void</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="nv">cancelAfterTrap</span><span class="p">:</span> <span class="kt">Bool</span> <span class="o">=</span> <span class="kc">false</span><span class="p">)</span> <span class="o">-&gt;</span> <span class="kt">DispatchSourceSignal</span></code></pre>
</div>
</div>
<div>
<h4>Parameters</h4>
<table class="graybox">
<tbody>
<tr>
<td>
<code>
<em>signal</em>
</code>
</td>
<td>
<div>
<p>The signal to trap.</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>handler</em>
</code>
</td>
<td>
<div>
<p>closure to invoke when the signal is captured.</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>on</em>
</code>
</td>
<td>
<div>
<p>DispatchQueue to run the signal handler on (default global dispatch queue)</p>
</div>
</td>
</tr>
<tr>
<td>
<code>
<em>cancelAfterTrap</em>
</code>
</td>
<td>
<div>
<p>Defaults to false, which means the signal handler can be run multiple times. If true, the DispatchSignalSource will be cancelled after being trapped once.</p>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div>
<h4>Return Value</h4>
<p>a <code>DispatchSourceSignal</code> for the given trap. The source must be cancelled by the caller.</p>
</div>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.10/Sources/Lifecycle/Lifecycle.swift#L343-L360">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle07ServiceA0V6SignalV"></a>
<a name="//apple_ref/swift/Struct/Signal" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle07ServiceA0V6SignalV">Signal</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p>A system signal</p>
<a href="../Structs/ServiceLifecycle/Signal.html" class="slightly-smaller">See more</a>
</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">struct</span> <span class="kt">Signal</span> <span class="p">:</span> <span class="kt">Equatable</span><span class="p">,</span> <span class="kt">CustomStringConvertible</span></code></pre>
</div>
</div>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.10/Sources/Lifecycle/Lifecycle.swift#L363-L389">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle0A14TasksContainerP8registeryySayAA0A4Task_pGF"></a>
<a name="//apple_ref/swift/Method/register(_:)" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle0A14TasksContainerP8registeryySayAA0A4Task_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">
</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">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 class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.10/Sources/Lifecycle/Lifecycle.swift#L393-L395">Show on GitHub</a>
</div>
</section>
</div>
</li>
<li class="item">
<div>
<code>
<a name="/s:9Lifecycle07ServiceA0V13ConfigurationV"></a>
<a name="//apple_ref/swift/Struct/Configuration" class="dashAnchor"></a>
<a class="token" href="#/s:9Lifecycle07ServiceA0V13ConfigurationV">Configuration</a>
</code>
</div>
<div class="height-container">
<div class="pointer-container"></div>
<section class="section">
<div class="pointer"></div>
<div class="abstract">
<p><code><a href="../Structs/ServiceLifecycle.html">ServiceLifecycle</a></code> configuration options.</p>
<a href="../Structs/ServiceLifecycle/Configuration.html" class="slightly-smaller">See more</a>
</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">struct</span> <span class="kt">Configuration</span></code></pre>
</div>
</div>
<div class="slightly-smaller">
<a href="https://github.com/swift-server/swift-service-lifecycle/tree/1.0.0-alpha.10/Sources/Lifecycle/Lifecycle.swift#L400-L423">Show on GitHub</a>
</div>
</section>
</div>
</li>
</ul>
</div>
</div>
</section>
</article>
</div>
<section class="footer">
<p>&copy; 2021 <a class="link" href="https://github.com/swift-server/swift-service-lifecycle" target="_blank" rel="external noopener">SwiftServiceLifecycle team</a>. All rights reserved. (Last updated: 2021-12-17)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.1</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
</section>
</body>
</html>