FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sourcegraph/internal/goroutine/example_test.go at main · oxenprogrammer/sourcegraph · GitHub
oxenprogrammer
/
sourcegraph
Public
forked from
sourcegraph/sourcegraph-public-snapshot
Notifications
You must be signed in to change notification settings
Fork
1
Star
1
Code
Pull requests
1
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sourcegraph
/
internal
/
goroutine
/
example_test.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (46 loc) · 1.04 KB
Breadcrumbs
sourcegraph
/
internal
/
goroutine
/
example_test.go
Copy path
File metadata and controls
60 lines (46 loc) · 1.04 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package
goroutine
import
(
"context"
"fmt"
"time"
)
type
exampleRoutine
struct
{
done
chan
struct
{}
}
func
(
m
*
exampleRoutine
)
Start
() {
for
{
select
{
case
<-
m
.
done
:
fmt
.
Println
(
"done!"
)
return
default
:
}
fmt
.
Println
(
"Hello there!"
)
time
.
Sleep
(
200
*
time
.
Millisecond
)
}
}
func
(
m
*
exampleRoutine
)
Stop
() {
m
.
done
<-
struct
{}{}
}
func
ExampleBackgroundRoutine
() {
r
:=
&
exampleRoutine
{
done
:
make
(
chan
struct
{}),
}
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
go
MonitorBackgroundRoutines
(
ctx
,
r
)
time
.
Sleep
(
500
*
time
.
Millisecond
)
cancel
()
time
.
Sleep
(
200
*
time
.
Millisecond
)
}
func
ExamplePeriodicGoroutine
() {
h
:=
NewHandlerWithErrorMessage
(
"example background routine"
,
func
(
ctx
context.
Context
)
error
{
fmt
.
Println
(
"Hello from the background!"
)
return
nil
})
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
r
:=
NewPeriodicGoroutine
(
ctx
,
200
*
time
.
Millisecond
,
h
)
go
MonitorBackgroundRoutines
(
ctx
,
r
)
time
.
Sleep
(
500
*
time
.
Millisecond
)
cancel
()
time
.
Sleep
(
200
*
time
.
Millisecond
)
}
Back
|
FazBrowse Home
|
New Git URL