weak

package
v1.8.2-0...-f7776fc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 2, 2024 License: GPL-2.0, GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package weak provides weak references for Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ref

type Ref struct {
	// contains filtered or unexported fields
}

Ref is a weak reference.

Create one with NewRef and retrieve referenced object with Get.

There must be no more than 1 weak reference to any object. Weak references must not be attached to an object on which runtime.SetFinalizer is also used. Weak references must not be copied.

func NewRef

func NewRef(obj interface{}) *Ref

NewRef creates new weak reference pointing to obj.

TODO + onrelease callback?

func (*Ref) Get

func (w *Ref) Get() (obj interface{})

Get returns object pointed to by this weak reference.

If original object is still alive - it is returned. If not - nil is returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL