All Projects → posener → context

posener / context

Licence: other
A proof of concept implementation of scoped context

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to context

retrygroup
Package retrygroup provides synchronization, Context cancelation for groups of retry goroutines working on subtasks of a common task.
Stars: ✭ 18 (+12.5%)
Mutual labels:  context, goroutine
captcha
Go package captcha generation and verification of image, Refer from https://github.com/dchest/captcha. Use captcha pool generation
Stars: ✭ 29 (+81.25%)
Mutual labels:  context, goroutine
Proof Of Concepts
A little collection of fun and creative proof of concepts to demonstrate the potential impact of a security vulnerability.
Stars: ✭ 148 (+825%)
Mutual labels:  proof-of-concept
errgroup
errgroup with goroutine worker limits
Stars: ✭ 143 (+793.75%)
Mutual labels:  goroutine
coldfusion-10-11-xss
Proof of Concept code for CVE-2015-0345 (APSB15-07)
Stars: ✭ 22 (+37.5%)
Mutual labels:  proof-of-concept
Yubitls
A Go TLS/HTTPS server demo that uses a Yubikey as the backend for it's private key
Stars: ✭ 168 (+950%)
Mutual labels:  proof-of-concept
workerpool
A workerpool that can get expanded & shrink dynamically.
Stars: ✭ 55 (+243.75%)
Mutual labels:  goroutine
Gopoc
用cel-go重现了长亭xray的poc检测功能的轮子
Stars: ✭ 124 (+675%)
Mutual labels:  proof-of-concept
Dapper.AmbientContext
Ambient context implementation for Dapper.NET
Stars: ✭ 31 (+93.75%)
Mutual labels:  context
react-context
(つ°ヮ°)つ Understanding React Context
Stars: ✭ 11 (-31.25%)
Mutual labels:  context
poc-github-actions
Various proofs of concept examples using Github Actions 🤖
Stars: ✭ 103 (+543.75%)
Mutual labels:  proof-of-concept
Investigo
🔎 Find usernames and download their data across social media.
Stars: ✭ 168 (+950%)
Mutual labels:  goroutine
Deephack
PoC code from DEF CON 25 presentation
Stars: ✭ 222 (+1287.5%)
Mutual labels:  proof-of-concept
Gltf To Usdz Research
Research and proof of concept of converting glTF to USDZ for AR Quick Look (iOS 12+).
Stars: ✭ 164 (+925%)
Mutual labels:  proof-of-concept
CVE-2021-4034
CVE-2021-4034: Local Privilege Escalation in polkit's pkexec proof of concept
Stars: ✭ 20 (+25%)
Mutual labels:  proof-of-concept
Spectre Meltdown Poc
A semi-demi-working proof of concept for a mix of spectre and meltdown vulnerabilities
Stars: ✭ 127 (+693.75%)
Mutual labels:  proof-of-concept
ray-tracing
This is a go implementation of the "Ray Tracing in One Weekend" book
Stars: ✭ 37 (+131.25%)
Mutual labels:  goroutine
BetterDiscordPlugins
🔥 My collection of Discord plugins for BetterDiscord, the Discord enhancement project
Stars: ✭ 120 (+650%)
Mutual labels:  proof-of-concept
elcontext
Context-based actions for Emacs
Stars: ✭ 18 (+12.5%)
Mutual labels:  context
interactor
Simple service objects for PHP
Stars: ✭ 36 (+125%)
Mutual labels:  context

context

Package context is a proof of concept implementation of scoped context, proposed in this blog post.

This library should not be used for production code.

Usage

The context package should be imported from github.com/posener/context.

 import (
-   "context"
+   "github.com/posener/context"
 )

Since this implementation does not involve changes to the runtime, the goroutine context must be initialized.

 func main() {
+	context.Init()
 	// Go code goes here.
 }

Functions should not anymore receive the context in the first argument. They should get it from the goroutine scope.

-func foo(ctx context.Context) {
+func foo() {
+	ctx := context.Get()
 	// Use context.
 }

Applying context to a scope:

unset := context.Set(ctx)
// ctx is applied until unset is called, or a deeper `Set` call.
unset()

Or:

defer context.Set(ctx)()
// ctx is applied until the end of the function or a deeper `Set` call.

Invoking goroutines should be done with context.Go or context.GoCtx

Running a new goroutine with the current stored context:

-go foo()
+context.Go(foo)

More complected functions:

-go foo(1, "hello")
+context.Go(func() { foo(1, "hello") })

Running a goroutine with a new context:

// `ctx` is the context that we want to have in the invoked goroutine
context.GoCtx(ctx, foo)

context.TODO should not be used anymore:

-f(context.TODO())
+f(context.Get())

Sub Packages


Created by goreadme

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].