@@ -231,26 +231,20 @@ type Reader interface {
231
231
io.Reader
232
232
io.WriterTo
233
233
234
- // Next returns a slice containing the next n bytes from the buffer,
235
- // advancing the buffer as if the bytes had been returned by Read.
236
- // Calling this method has the same effect as calling Peek and Discard.
237
- // If the number of the available bytes is less than requested, a pair of (0, io.ErrShortBuffer)
238
- // is returned.
234
+ // Next returns the next n bytes and advance the inbound buffer.
235
+ // buf must not be used in a new goroutine. Otherwise, use Read instead.
239
236
//
240
- // Note that the []byte buf returned by Next() is not allowed to be passed to a new goroutine,
241
- // as this []byte will be reused within event-loop.
242
- // If you have to use buf in a new goroutine, then you need to make a copy of buf and pass this copy
243
- // to that new goroutine.
237
+ // If the number of the available bytes is less than requested,
238
+ // a pair of (0, io.ErrShortBuffer) is returned.
244
239
Next (n int ) (buf []byte , err error )
245
240
246
- // Peek returns the next n bytes without advancing the inbound buffer, the returned bytes
247
- // remain valid until a Discard is called. If the number of the available bytes is
248
- // less than requested, a pair of (0, io.ErrShortBuffer) is returned.
241
+ // Peek returns the next n bytes without advancing the inbound buffer,
242
+ // the returned bytes remain valid until a Discard is called.
243
+ // buf must neither be used in a new goroutine nor anywhere after the call
244
+ // to Discard, make a copy of buf manually or use Read otherwise.
249
245
//
250
- // Note that the []byte buf returned by Peek() is not allowed to be passed to a new goroutine,
251
- // as this []byte will be reused within event-loop.
252
- // If you have to use buf in a new goroutine, then you need to make a copy of buf and pass this copy
253
- // to that new goroutine.
246
+ // If the number of the available bytes is less than requested,
247
+ // a pair of (0, io.ErrShortBuffer) is returned.
254
248
Peek (n int ) (buf []byte , err error )
255
249
256
250
// Discard advances the inbound buffer with next n bytes, returning the number of bytes discarded.
@@ -497,20 +491,17 @@ type (
497
491
498
492
// OnTraffic fires when a socket receives data from the remote.
499
493
//
500
- // Note that the []byte returned from Conn.Peek(int)/Conn.Next(int) is not allowed to be passed to a new goroutine,
501
- // as this []byte will be reused within event-loop after OnTraffic() returns.
502
- // If you have to use this []byte in a new goroutine, you should either make a copy of it or call Conn.Read([]byte)
503
- // to read data into your own []byte, then pass the new []byte to the new goroutine.
494
+ // Also check out the comments on Reader and Writer interfaces.
504
495
OnTraffic (c Conn ) (action Action )
505
496
506
497
// OnTick fires immediately after the engine starts and will fire again
507
498
// following the duration specified by the delay return value.
508
499
OnTick () (delay time.Duration , action Action )
509
500
}
510
501
511
- // BuiltinEventEngine is a built-in implementation of EventHandler which sets up each method with a default implementation,
512
- // you can compose it with your own implementation of EventHandler when you don't want to implement all methods
513
- // in EventHandler.
502
+ // BuiltinEventEngine is a built-in implementation of EventHandler which sets up
503
+ // each method with a default implementation, you can compose it with your own
504
+ // implementation of EventHandler when you don't want to implement all methods in EventHandler.
514
505
BuiltinEventEngine struct {}
515
506
)
516
507
0 commit comments