Skip to content

Instantly share code, notes, and snippets.

use anyhow::Result;
use clap::Parser;
use rand::{
distributions::{Alphanumeric, DistString},
Rng,
};
use rdkafka::{
config::ClientConfig,
consumer::{BaseConsumer, CommitMode, Consumer, ConsumerContext},
error::KafkaError,

Keybase proof

I hereby claim:

  • I am mlowicki on github.
  • I am mlowicki (https://keybase.io/mlowicki) on keybase.
  • I have a public key ASCscE1TxlKFBA34WFPo5lFyE90paa80JKBpnQ13RUg7kQo

To claim this, I am signing this object:

> go install github.com/mlowicki/lab && ./bin/lab
Start f
Start g
Start h
3rd deferred in h
2nd deferred in h
Panic found: boom!
1st deferred in h
End g
Deferred in g
package main
import "fmt"
func f() {
fmt.Println("Start f")
defer func() {
fmt.Println("Deferred in f")
}()
g()
> go install github.com/mlowicki/lab && ./bin/lab
Deferred by h
Deferred by g
Deferred by f
panic: boom!
panic: 2nd explosion!
goroutine 5 [running]:
panic(0xb8480, 0x8201c82d0)
/usr/local/go/src/runtime/panic.go:481 +0x3e6
import "fmt"
func f(ch chan int) {
defer func() {
fmt.Println("Deferred by f")
}()
g()
ch <- 0
}
> go install github.com/mlowicki/lab && ./bin/lab
Deferred by h
Deferred by g
Deferred by f
panic: boom!
goroutine 17 [running]:
panic(0xb83e0, 0x820220050)
/usr/local/go/src/runtime/panic.go:481 +0x3e6
main.h()
package main
import "fmt"
func f(ch chan int) {
defer func() {
fmt.Println("Deferred by f")
}()
g()
ch <- 0
> go install github.com/mlowicki/lab && ./bin/lab
f() == 0
g() == 1
import "fmt"
func f() int {
n := 0
defer func() {
n++
}()
return n
}