Skip to content

Sincerely ask, is this redundant? #2923

@Trinoooo

Description

@Trinoooo

Version:Latest, v1.43.2
Description:

func safeAsyncClose(b *Broker) {
	tmp := b // local var prevents clobbering in goroutine
	go withRecover(func() {
		if connected, _ := tmp.Connected(); connected {
			if err := tmp.Close(); err != nil {
				Logger.Println("Error closing broker", tmp.ID(), ":", err)
			}
		}
	})
}

annotation says "local var prevents clobbering in goroutine", how it works? I mean when safeAsyncClose is called, the local var b is just a copy pointing to the Broker, even if goroutine overwrites b, other goroutines will not perceive it.

thanks for help :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions