Giter Club home page Giter Club logo

ctx's Introduction

ctx

Composable utilities for Go contexts.

Godoc Reference Go Report Card

Installation

go get -u github.com/SentimensRG/ctx

Overview

The ctx package provides utilites for working with data structures satisfying the ctx.Doner interface, most notably context.Context:

type Doner interface {
    Done() <-chan struct{}
}

The functions in ctx are appropriate for operations that do not preserve the values in a context, e.g.: joining several contexts together.

Subpackages

  • sigctx: contexts for graceful shutdown
  • refctx: contexts linked to a reference-counter
  • mergectx: utilities for merging context.Context instances while preserving values, errors and deadlines.

RFC

If you find this useful please let me know: [email protected]

Seriously, even if you just used it in your weekend project, I'd like to hear about it :)

License

The MIT License

Copyright (c) 2017 Sentimens Research Group, LLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

ctx's People

Contributors

lthibault avatar orisano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ctx's Issues

sigctx: SIGINT won't exit

@lthibault Opening a new issue per discussion in #4. The import side-effect is now resolved (awesome!) but I'm still seeing the signal.Stop() issue. Here is my test program again:

package main

import (
	"log"
	"os"
	"time"

	"github.com/SentimensRG/ctx/sigctx" // ctrl-c will not work if you pass `server` as an arg
	//"github.com/mhupman/ctx/sigctx" // ctrl-c will work in either case
)

func main() {
	if len(os.Args) > 1 && os.Args[1] == "server" {
		go startServer()
	}

	log.Println("starting some kind of long running op - ctrl-c to quit me!")
	for {
		time.Sleep(time.Second)
	}
}

func startServer() {
	log.Println("starting server")
	<-sigctx.New().Done()
	log.Println("server done")
}

No matter how many times I ctrl-c, it hangs. If I add a signal.Stop(sigCh) on sigctx/sigctx.go#38 it seems to fix the problem and SIGINTs will cause a program exit.

Unit tests

$ go test -cover -race ./...                                                              (328ms) 
ok  	github.com/SentimensRG/ctx	1.035s	coverage: 73.0% of statements
ok  	github.com/SentimensRG/ctx/mergectx	1.711s	coverage: 54.0% of statements
ok  	github.com/SentimensRG/ctx/refctx	1.032s	coverage: 75.0% of statements
?   	github.com/SentimensRG/ctx/sigctx	[no test files]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.