Rename to shorter context

This commit is contained in:
Mark McGranaghan 2020-01-04 09:50:52 -08:00
parent 061f69cb98
commit df99089b9f
9 changed files with 15 additions and 15 deletions

View File

@ -68,7 +68,7 @@ Command-Line Subcommands
Environment Variables
HTTP Clients
HTTP Servers
Context in HTTP Servers
Context
Spawning Processes
Exec'ing Processes
Signals

View File

@ -1,2 +0,0 @@
50f0c85266d1f8f546242ce8f8caf27732e99dff
h1gVSe70R00

View File

@ -25,7 +25,7 @@ func hello(w http.ResponseWriter, req *http.Request) {
// `Done()` channel for a signal that we should cancel
// the work and return as soon as possible.
select {
case <-time.After(3 * time.Second):
case <-time.After(10 * time.Second):
fmt.Fprintf(w, "hello\n")
case <-ctx.Done():
err := ctx.Err()

View File

@ -0,0 +1,2 @@
a899a68d131b0f8cf3ae846ef728877d2407d219
9fUzFC2uyFk

View File

@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>Go by Example: Context in HTTP Servers</title>
<title>Go by Example: Context</title>
<link rel=stylesheet href="site.css">
</head>
<script>
@ -20,8 +20,8 @@
}
</script>
<body>
<div class="example" id="context-in-http-servers">
<h2><a href="./">Go by Example</a>: Context in HTTP Servers</h2>
<div class="example" id="context">
<h2><a href="./">Go by Example</a>: Context</h2>
<table>
@ -34,7 +34,7 @@ controlling cancellation.</p>
</td>
<td class="code leading">
<a href="http://play.golang.org/p/h1gVSe70R00"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
<a href="http://play.golang.org/p/9fUzFC2uyFk"><img title="Run code" src="play.png" class="run" /></a><img title="Copy code" src="clipboard.png" class="copy" />
<div class="highlight"><pre><span class="kn">package</span> <span class="nx">main</span>
</pre></div>
@ -98,7 +98,7 @@ the work and return as soon as possible.</p>
<td class="code leading">
<div class="highlight"><pre> <span class="k">select</span> <span class="p">{</span>
<span class="k">case</span> <span class="o">&lt;-</span><span class="nx">time</span><span class="p">.</span><span class="nx">After</span><span class="p">(</span><span class="mi">3</span> <span class="o">*</span> <span class="nx">time</span><span class="p">.</span><span class="nx">Second</span><span class="p">):</span>
<span class="k">case</span> <span class="o">&lt;-</span><span class="nx">time</span><span class="p">.</span><span class="nx">After</span><span class="p">(</span><span class="mi">10</span> <span class="o">*</span> <span class="nx">time</span><span class="p">.</span><span class="nx">Second</span><span class="p">):</span>
<span class="nx">fmt</span><span class="p">.</span><span class="nx">Fprintf</span><span class="p">(</span><span class="nx">w</span><span class="p">,</span> <span class="s">&quot;hello\n&quot;</span><span class="p">)</span>
<span class="k">case</span> <span class="o">&lt;-</span><span class="nx">ctx</span><span class="p">.</span><span class="nx">Done</span><span class="p">():</span>
<span class="nx">err</span> <span class="o">:=</span> <span class="nx">ctx</span><span class="p">.</span><span class="nx">Err</span><span class="p">()</span>
@ -184,12 +184,12 @@ cancellation.</p>
</p>
<p class="footer">
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/context-in-http-servers">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
by <a href="https://markmcgranaghan.com">Mark McGranaghan</a> | <a href="https://github.com/mmcgrana/gobyexample/blob/master/examples/context">source</a> | <a href="https://github.com/mmcgrana/gobyexample#license">license</a>
</p>
</div>
<script>
var codeLines = [];
codeLines.push('package main\u000A');codeLines.push('import (\u000A \"fmt\"\u000A \"net/http\"\u000A \"time\"\u000A)\u000A');codeLines.push('func hello(w http.ResponseWriter, req *http.Request) {\u000A');codeLines.push(' ctx := req.Context()\u000A fmt.Println(\"server: hello handler started\")\u000A defer fmt.Println(\"server: hello handler ended\")\u000A');codeLines.push(' select {\u000A case \x3C-time.After(3 * time.Second):\u000A fmt.Fprintf(w, \"hello\\n\")\u000A case \x3C-ctx.Done():\u000A err := ctx.Err()\u000A fmt.Println(\"server:\", err)\u000A internalError := http.StatusInternalServerError\u000A http.Error(w, err.Error(), internalError)\u000A }\u000A}\u000A');codeLines.push('func main() {\u000A');codeLines.push(' http.HandleFunc(\"/hello\", hello)\u000A http.ListenAndServe(\":8090\", nil)\u000A}\u000A');codeLines.push('');codeLines.push('');
codeLines.push('package main\u000A');codeLines.push('import (\u000A \"fmt\"\u000A \"net/http\"\u000A \"time\"\u000A)\u000A');codeLines.push('func hello(w http.ResponseWriter, req *http.Request) {\u000A');codeLines.push(' ctx := req.Context()\u000A fmt.Println(\"server: hello handler started\")\u000A defer fmt.Println(\"server: hello handler ended\")\u000A');codeLines.push(' select {\u000A case \x3C-time.After(10 * time.Second):\u000A fmt.Fprintf(w, \"hello\\n\")\u000A case \x3C-ctx.Done():\u000A err := ctx.Err()\u000A fmt.Println(\"server:\", err)\u000A internalError := http.StatusInternalServerError\u000A http.Error(w, err.Error(), internalError)\u000A }\u000A}\u000A');codeLines.push('func main() {\u000A');codeLines.push(' http.HandleFunc(\"/hello\", hello)\u000A http.ListenAndServe(\":8090\", nil)\u000A}\u000A');codeLines.push('');codeLines.push('');
</script>
<script src="site.js" async></script>
</body>

4
public/http-servers generated
View File

@ -14,7 +14,7 @@
if (e.key == "ArrowRight") {
window.location.href = 'context-in-http-servers';
window.location.href = 'context';
}
}
@ -201,7 +201,7 @@ router we&rsquo;ve just set up.</p>
<p class="next">
Next example: <a href="context-in-http-servers">Context in HTTP Servers</a>.
Next example: <a href="context">Context</a>.
</p>
<p class="footer">

2
public/index.html generated
View File

@ -163,7 +163,7 @@
<li><a href="http-servers">HTTP Servers</a></li>
<li><a href="context-in-http-servers">Context in HTTP Servers</a></li>
<li><a href="context">Context</a></li>
<li><a href="spawning-processes">Spawning Processes</a></li>

View File

@ -9,7 +9,7 @@
onkeydown = (e) => {
if (e.key == "ArrowLeft") {
window.location.href = 'context-in-http-servers';
window.location.href = 'context';
}