Skip to content

Weak is a tiny Go package providing primitives for creating weak references.

Notifications You must be signed in to change notification settings

jdeflander/weak

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Weak

Weak is a tiny Go package providing primitives for creating weak references.

Installation

go get github.com/jdeflander/weak

Usage

package main

import (
	"fmt"
	"runtime"

	"github.com/jdeflander/weak"
)

func main() {
	v := weak.NewValue(42)
	r := v.Reference()

	printReference(r)
	runtime.KeepAlive(v)

	runtime.GC()
	printReference(r)
	// Output:
	// 42 true
	// <nil> false
}

func printReference(reference weak.Reference) {
	i, ok := reference.Get()
	fmt.Println(i, ok)
}

About

Weak is a tiny Go package providing primitives for creating weak references.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages