You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: gbytes/buffer.go
+11-6Lines changed: 11 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,6 @@ Subsequent matches against the buffer will only operate against data that appear
7
7
8
8
The read cursor is an opaque implementation detail that you cannot access. You should use the Say matcher to sift through the buffer. You can always
9
9
access the entire buffer's contents with Contents().
10
-
11
10
*/
12
11
package gbytes
13
12
@@ -29,7 +28,7 @@ type Buffer struct {
29
28
contents []byte
30
29
readCursoruint64
31
30
lock*sync.Mutex
32
-
detectCloserchaninterface{}
31
+
detectCloserchanany
33
32
closedbool
34
33
}
35
34
@@ -167,19 +166,25 @@ You could do something like:
167
166
168
167
select {
169
168
case <-buffer.Detect("You are not logged in"):
169
+
170
170
//log in
171
+
171
172
case <-buffer.Detect("Success"):
173
+
172
174
//carry on
175
+
173
176
case <-time.After(time.Second):
174
-
//welp
175
-
}
177
+
178
+
//welp
179
+
}
180
+
176
181
buffer.CancelDetects()
177
182
178
183
You should always call CancelDetects after using Detect. This will close any channels that have not detected and clean up the goroutines that were spawned to support them.
179
184
180
185
Finally, you can pass detect a format string followed by variadic arguments. This will construct the regexp using fmt.Sprintf.
0 commit comments