Skip to content

Commit 2b91da3

Browse files
committed
fix gofmt
1 parent faa1110 commit 2b91da3

File tree

4 files changed

+77
-77
lines changed

4 files changed

+77
-77
lines changed

examples/drop_oldest/main.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
package main
22

33
import (
4-
"context"
5-
"fmt"
6-
"time"
4+
"context"
5+
"fmt"
6+
"time"
77

8-
"github.com/Raezil/GoEventBus"
8+
"github.com/Raezil/GoEventBus"
99
)
1010

1111
// OverrunPolicy=DropOldest silently discards events.
1212
func main() {
13-
dispatcher := GoEventBus.Dispatcher{
14-
"noop": func(ctx context.Context, _ map[string]any) (GoEventBus.Result, error) {
15-
time.Sleep(80 * time.Millisecond)
16-
return GoEventBus.Result{}, nil
17-
},
18-
}
19-
store := GoEventBus.NewEventStore(&dispatcher, 2, GoEventBus.DropOldest)
13+
dispatcher := GoEventBus.Dispatcher{
14+
"noop": func(ctx context.Context, _ map[string]any) (GoEventBus.Result, error) {
15+
time.Sleep(80 * time.Millisecond)
16+
return GoEventBus.Result{}, nil
17+
},
18+
}
19+
store := GoEventBus.NewEventStore(&dispatcher, 2, GoEventBus.DropOldest)
2020

21-
for i := 0; i < 5; i++ {
22-
_ = store.Subscribe(context.Background(), GoEventBus.Event{
23-
ID: fmt.Sprintf("D-%d", i),
24-
Projection: "noop",
25-
})
26-
}
21+
for i := 0; i < 5; i++ {
22+
_ = store.Subscribe(context.Background(), GoEventBus.Event{
23+
ID: fmt.Sprintf("D-%d", i),
24+
Projection: "noop",
25+
})
26+
}
2727

28-
store.Publish()
29-
time.Sleep(200 * time.Millisecond)
28+
store.Publish()
29+
time.Sleep(200 * time.Millisecond)
3030

31-
pub, proc, errs := store.Metrics()
32-
fmt.Printf("published=%d processed=%d errors=%d\n", pub, proc, errs)
31+
pub, proc, errs := store.Metrics()
32+
fmt.Printf("published=%d processed=%d errors=%d\n", pub, proc, errs)
3333
}

examples/handler_timeout/main.go

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
package main
22

33
import (
4-
"context"
5-
"fmt"
6-
"time"
4+
"context"
5+
"fmt"
6+
"time"
77

8-
"github.com/Raezil/GoEventBus"
8+
"github.com/Raezil/GoEventBus"
99
)
1010

1111
// Handler runs for 150 ms unless its context is cancelled.
1212
func main() {
13-
dispatcher := GoEventBus.Dispatcher{
14-
"demo": func(ctx context.Context, _ map[string]any) (GoEventBus.Result, error) {
15-
select {
16-
case <-time.After(150 * time.Millisecond):
17-
fmt.Println("handler OK")
18-
return GoEventBus.Result{Message: "ok"}, nil
19-
case <-ctx.Done():
20-
fmt.Println("handler cancelled:", ctx.Err())
21-
return GoEventBus.Result{}, ctx.Err()
22-
}
23-
},
24-
}
25-
26-
store := GoEventBus.NewEventStore(&dispatcher, 4, GoEventBus.Block)
27-
28-
// Handler‑only 40 ms timeout → will cancel.
29-
hctx, cancel := context.WithTimeout(context.Background(), 40*time.Millisecond)
30-
defer cancel()
31-
32-
_ = store.Subscribe(context.Background(), GoEventBus.Event{
33-
ID: "H-1", Projection: "demo", Args: map[string]any{"__ctx": hctx},
34-
})
35-
36-
store.Publish()
37-
time.Sleep(60 * time.Millisecond)
38-
39-
pub, proc, errs := store.Metrics()
40-
fmt.Printf("published=%d processed=%d errors=%d\n", pub, proc, errs)
13+
dispatcher := GoEventBus.Dispatcher{
14+
"demo": func(ctx context.Context, _ map[string]any) (GoEventBus.Result, error) {
15+
select {
16+
case <-time.After(150 * time.Millisecond):
17+
fmt.Println("handler OK")
18+
return GoEventBus.Result{Message: "ok"}, nil
19+
case <-ctx.Done():
20+
fmt.Println("handler cancelled:", ctx.Err())
21+
return GoEventBus.Result{}, ctx.Err()
22+
}
23+
},
24+
}
25+
26+
store := GoEventBus.NewEventStore(&dispatcher, 4, GoEventBus.Block)
27+
28+
// Handler‑only 40 ms timeout → will cancel.
29+
hctx, cancel := context.WithTimeout(context.Background(), 40*time.Millisecond)
30+
defer cancel()
31+
32+
_ = store.Subscribe(context.Background(), GoEventBus.Event{
33+
ID: "H-1", Projection: "demo", Args: map[string]any{"__ctx": hctx},
34+
})
35+
36+
store.Publish()
37+
time.Sleep(60 * time.Millisecond)
38+
39+
pub, proc, errs := store.Metrics()
40+
fmt.Printf("published=%d processed=%d errors=%d\n", pub, proc, errs)
4141
}

examples/publisher_timeout/main.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
package main
22

33
import (
4-
"context"
5-
"fmt"
6-
"time"
4+
"context"
5+
"fmt"
6+
"time"
77

8-
"github.com/Raezil/GoEventBus"
8+
"github.com/Raezil/GoEventBus"
99
)
1010

1111
// Shows back‑pressure timeout when the buffer is full.
1212
func main() {
13-
dispatcher := GoEventBus.Dispatcher{}
14-
store := GoEventBus.NewEventStore(&dispatcher, 1, GoEventBus.Block)
13+
dispatcher := GoEventBus.Dispatcher{}
14+
store := GoEventBus.NewEventStore(&dispatcher, 1, GoEventBus.Block)
1515

16-
// Fill the single slot.
17-
_ = store.Subscribe(context.Background(), GoEventBus.Event{ID: "P-0"})
16+
// Fill the single slot.
17+
_ = store.Subscribe(context.Background(), GoEventBus.Event{ID: "P-0"})
1818

19-
// Next publish must wait; we give it only 30 ms.
20-
pubCtx, cancel := context.WithTimeout(context.Background(), 30*time.Millisecond)
21-
defer cancel()
19+
// Next publish must wait; we give it only 30 ms.
20+
pubCtx, cancel := context.WithTimeout(context.Background(), 30*time.Millisecond)
21+
defer cancel()
2222

23-
err := store.Subscribe(pubCtx, GoEventBus.Event{ID: "P-1"})
24-
fmt.Println("Subscribe error:", err)
23+
err := store.Subscribe(pubCtx, GoEventBus.Event{ID: "P-1"})
24+
fmt.Println("Subscribe error:", err)
2525

26-
pub, proc, errs := store.Metrics()
27-
fmt.Printf("published=%d processed=%d errors=%d\n", pub, proc, errs)
26+
pub, proc, errs := store.Metrics()
27+
fmt.Printf("published=%d processed=%d errors=%d\n", pub, proc, errs)
2828
}

examples/return_error/main.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package main
22

33
import (
4-
"context"
5-
"fmt"
4+
"context"
5+
"fmt"
66

7-
"github.com/Raezil/GoEventBus"
7+
"github.com/Raezil/GoEventBus"
88
)
99

1010
// Demonstrates OverrunPolicy=ReturnError (fail fast).
1111
func main() {
12-
dispatcher := GoEventBus.Dispatcher{}
13-
store := GoEventBus.NewEventStore(&dispatcher, 2, GoEventBus.ReturnError)
12+
dispatcher := GoEventBus.Dispatcher{}
13+
store := GoEventBus.NewEventStore(&dispatcher, 2, GoEventBus.ReturnError)
1414

15-
_ = store.Subscribe(context.Background(), GoEventBus.Event{ID: "R-0"})
16-
_ = store.Subscribe(context.Background(), GoEventBus.Event{ID: "R-1"}) // buffer full
15+
_ = store.Subscribe(context.Background(), GoEventBus.Event{ID: "R-0"})
16+
_ = store.Subscribe(context.Background(), GoEventBus.Event{ID: "R-1"}) // buffer full
1717

18-
err := store.Subscribe(context.Background(), GoEventBus.Event{ID: "R-2"})
19-
fmt.Println("Subscribe error:", err)
18+
err := store.Subscribe(context.Background(), GoEventBus.Event{ID: "R-2"})
19+
fmt.Println("Subscribe error:", err)
2020
}

0 commit comments

Comments
 (0)