A Go library providing ThreadLocal-like coroutine context storage and goroutine ID access with inheritance support.
Routine is a Go library that provides goroutine-local storage, enabling developers to access and manage coroutine context information more elegantly. It addresses the lack of ThreadLocal functionality in Go by offering non-competitive, high-performance interfaces for coroutine context access, serving as an alternative to pervasive Context parameter passing.
Go developers who need to manage per-goroutine state or context, particularly those migrating from languages like Java or C++ that have ThreadLocal and require similar functionality in concurrent Go applications.
Developers choose Routine over alternatives because it directly provides high-performance goroutine-local storage with inheritable context variables, avoiding the need to pass Context parameters through every function call. Its unique selling point is enabling ThreadLocal-like behavior in Go with cross-platform support and automatic inheritance when spawning new goroutines.
ThreadLocal for Golang.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses assembly code across multiple architectures to retrieve goid with performance five times faster than rand.Int(), as documented in the README.
Provides NewInheritableThreadLocal to automatically copy or capture context variables when spawning goroutines via Go() or WrapTask() functions, enabling seamless state inheritance.
Supports a wide range of OS and architecture combinations including Linux, Windows, macOS, and WebAssembly, detailed in the project's support grid.
Functions like Go() and WrapTask() catch panics in child goroutines, print stack traces, and re-throw errors when awaited, simplifying error management in concurrent code.
The static mode in version 1.1.5 requires additional compiler parameters (-a -toolexec='routinex -v'), adding setup complexity and potential toolchain dependencies.
Deviates from Go's idiomatic use of Context for state propagation, which could lead to code that is harder to maintain or integrate with standard libraries and frameworks.
Allocates a thread structure for each goroutine, adding memory usage that is only collected after goroutine exit and GC, as explained in the Garbage Collection section.