Skip to content

Conversation

joamaki
Copy link
Contributor

@joamaki joamaki commented Jan 25, 2024

Buffer operator collects items into a user-defined buffer, which is emitted when the buffer is full or when a given time interval has elapsed.

Example:

var src Observable[string] // Some stream of strings

sliceBuffered := stream.Buffer[[]string, string](
  src,
  16, // buffer size
  time.Second, // wait up to 1 second for 16 items
  func(buf []string, s string) []string {
    return append(buf, s)
  })

mapBuffered := stream.Buffer[map[string]struct{}, string](
  src,
  16, // buffer size
  time.Second, // wait up to 1 second for 16 items
  func(buf map[string]struct{}, s string) map[string]struct{} {
    if buf == nil {
      return map[string]struct{}{s: struct{}{}}
    }
    buf[s] = struct{}{}
    return buf
  })

Buffer operator collects items into a user-defined buffer,
which is emitted when the buffer is full or when a given
time interval has elapsed.

Example:

    var src Observable[string] // Some stream of strings

    sliceBuffered := stream.Buffer[[]string, string](
      src,
      16, // buffer size
      time.Second, // wait up to 1 second for 16 items
      func(buf []string, s string) []string {
        return append(buf, s)
      })

    mapBuffered := stream.Buffer[map[string]struct{}, string](
      src,
      16, // buffer size
      time.Second, // wait up to 1 second for 16 items
      func(buf map[string]struct{}, s string) map[string]struct{} {
        if buf == nil {
          return map[string]struct{}{s: struct{}{}}
        }
        buf[s] = struct{}{}
        return buf
      })

Signed-off-by: Jussi Maki <jussi@isovalent.com>
@joamaki joamaki requested a review from a team as a code owner January 25, 2024 14:32
@joamaki joamaki requested a review from pippolo84 January 25, 2024 14:32
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Jan 25, 2024
@joamaki joamaki added the release-note/misc This PR makes changes that have no direct user impact. label Jan 25, 2024
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Jan 25, 2024
Copy link
Member

@pippolo84 pippolo84 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@joamaki
Copy link
Contributor Author

joamaki commented Jan 26, 2024

/test

@joamaki joamaki enabled auto-merge January 26, 2024 12:08
@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jan 26, 2024
@joamaki joamaki added this pull request to the merge queue Jan 26, 2024
Merged via the queue into cilium:main with commit d72e630 Jan 26, 2024
@joamaki joamaki deleted the pr/joamaki/stream-buffer-operator branch January 26, 2024 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants