mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
refactor: remove helpers deprecated for more than 3y
This commit is contained in:
@@ -7,10 +7,8 @@ subCategory: channel
|
||||
signatures:
|
||||
- "func Buffer[T any](ch <-chan T, size int) (collection []T, length int, readTime time.Duration, ok bool)"
|
||||
- "func BufferWithContext[T any](ctx context.Context, ch <-chan T, size int) (collection []T, length int, readTime time.Duration, ok bool)"
|
||||
- "func Batch[T any](ch <-chan T, size int) (collection []T, length int, readTime time.Duration, ok bool)"
|
||||
variantHelpers:
|
||||
- core#channel#buffer
|
||||
- core#channel#batch
|
||||
- core#channel#bufferwithcontext
|
||||
similarHelpers:
|
||||
- core#channel#slicetochannel
|
||||
@@ -34,24 +32,6 @@ items, length, readTime, ok := lo.Buffer(ch, 3)
|
||||
// ok: true (channel was closed)
|
||||
```
|
||||
|
||||
### Batch (Deprecated)
|
||||
|
||||
Batch is an alias for Buffer.
|
||||
|
||||
```go
|
||||
ch := make(chan string, 5)
|
||||
ch <- "a"
|
||||
ch <- "b"
|
||||
ch <- "c"
|
||||
close(ch)
|
||||
|
||||
batch, length, readTime, ok := lo.Batch(ch, 2)
|
||||
// batch: []string{"a", "b"}
|
||||
// length: 2
|
||||
// readTime: ~0s (immediate read from buffered channel)
|
||||
// ok: true (channel was closed)
|
||||
```
|
||||
|
||||
### BufferWithContext
|
||||
|
||||
BufferWithContext reads up to size items from a channel with context cancellation.
|
||||
|
||||
@@ -6,10 +6,8 @@ category: core
|
||||
subCategory: channel
|
||||
signatures:
|
||||
- "func BufferWithTimeout[T any](ch <-chan T, size int, timeout time.Duration) (collection []T, length int, readTime time.Duration, ok bool)"
|
||||
- "func BatchWithTimeout[T any](ch <-chan T, size int, timeout time.Duration) (collection []T, length int, readTime time.Duration, ok bool)"
|
||||
variantHelpers:
|
||||
- core#channel#bufferwithtimeout
|
||||
- core#channel#batchwithtimeout
|
||||
similarHelpers:
|
||||
- core#channel#buffer
|
||||
- core#channel#bufferwithcontext
|
||||
@@ -30,18 +28,3 @@ go func() {
|
||||
items, length, readTime, ok := lo.BufferWithTimeout(ch, 5, 100*time.Millisecond)
|
||||
// Returns empty slice due to timeout
|
||||
```
|
||||
|
||||
### BatchWithTimeout (Deprecated)
|
||||
|
||||
BatchWithTimeout is an alias for BufferWithTimeout.
|
||||
|
||||
```go
|
||||
ch := make(chan float64)
|
||||
go func() {
|
||||
time.Sleep(150 * time.Millisecond)
|
||||
ch <- 3.14
|
||||
}()
|
||||
|
||||
batch, length, readTime, ok := lo.BatchWithTimeout(ch, 3, 100*time.Millisecond)
|
||||
// Returns empty slice due to timeout
|
||||
```
|
||||
@@ -1,34 +0,0 @@
|
||||
---
|
||||
name: ChannelMerge
|
||||
slug: channelmerge
|
||||
sourceRef: channel.go#L18
|
||||
category: core
|
||||
subCategory: channel
|
||||
signatures:
|
||||
- "func ChannelMerge[T any](channelBufferCap int, upstreams ...<-chan T) <-chan T"
|
||||
similarHelpers:
|
||||
- core#channel#fanin
|
||||
- core#channel#fanout
|
||||
- core#channel#channeldispatcher
|
||||
position: 255
|
||||
---
|
||||
|
||||
ChannelMerge merges multiple channels into a single channel.
|
||||
|
||||
```go
|
||||
ch1 := make(chan int, 2)
|
||||
ch2 := make(chan int, 2)
|
||||
ch1 <- 1
|
||||
ch1 <- 2
|
||||
ch2 <- 3
|
||||
ch2 <- 4
|
||||
close(ch1)
|
||||
close(ch2)
|
||||
|
||||
merged := lo.ChannelMerge(10, ch1, ch2)
|
||||
var result []int
|
||||
for item := range merged {
|
||||
result = append(result, item)
|
||||
}
|
||||
// result contains [1, 2, 3, 4] (order may vary)
|
||||
```
|
||||
@@ -7,8 +7,6 @@ subCategory: string
|
||||
playUrl: https://go.dev/play/p/qE93rgqe1TW
|
||||
variantHelpers:
|
||||
- core#string#ellipsis
|
||||
# typo / deprecated
|
||||
- core#string#elipse
|
||||
similarHelpers:
|
||||
- core#string#substring
|
||||
- core#string#runelength
|
||||
|
||||
@@ -8,7 +8,6 @@ signatures:
|
||||
- "func FanIn[T any](channelBufferCap int, upstreams ...<-chan T) <-chan T"
|
||||
similarHelpers:
|
||||
- core#channel#fanout
|
||||
- core#channel#channelmerge
|
||||
- core#channel#channeldispatcher
|
||||
position: 254
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user