2024-08-06 16:54:34 +01:00
2024-08-07 15:50:19 +01:00
2024-08-07 13:57:44 +01:00
2024-08-06 15:15:21 +01:00
2024-08-06 15:15:21 +01:00
2024-08-06 15:18:34 +01:00
2024-08-06 15:15:21 +01:00
2024-08-07 13:22:04 +00:00
2024-08-07 14:17:20 +01:00
2024-08-07 15:50:19 +01:00
2024-08-07 15:50:19 +01:00
2024-08-06 15:15:21 +01:00

GubGub

Yet another in-memory Go PubSub library. I started to develop what is now GubGub in one of my personal projects but I soon found myself using it in other completely unrelated projects and I thought it could be a nice thing to share. It might be very tailored to my personal preferences but my focus was concurrency safety and ease of usage.

Getting started

go get -u gitlab.com/naterciom/gubgub

Example

package main

import (
	"context"
	"fmt"
	"time"

	"gitlab.com/naterciom/gubgub"
)

type MyMessage struct {
	Name string
}

func consumer(msg MyMessage) {
    fmt.Printf("Hello %s", msg.Name)
}

func main() {
	ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
	defer cancel()

	topic := gubgub.NewAsyncTopic[MyMessage](ctx)

	topic.Subscribe(gubgub.Forever(consumer))

    // The AsyncTopic doesn't wait for the subscriber to be registered so, for the purposes of this
    // example, we sleep on it.
	time.Sleep(time.Millisecond)

	topic.Publish(MyMessage{Name: "John Smith"})

	<-ctx.Done()
}
Description
Yet another in-memory Go PubSub library.
Readme MIT 3.1 MiB
Languages
Go 100%