styx: aqwari.net/net/styx/internal/util Index | Examples | Files

package util

import "aqwari.net/net/styx/internal/util"

Package util contains internal routines used by the styx packages.

Index

Examples

Package Files

blackhole.go doc.go errors.go refcount.go sectionwriter.go

func IsTempErr Uses

func IsTempErr(err error) bool

IsTempErr returns true if an error exports a Temporary() method that returns true.

type BlackHole Uses

type BlackHole struct{}

A BlackHole is an io.ReadWriteCloser that accepts an infinite amount of input and produces no output.

func (BlackHole) Close Uses

func (BlackHole) Close() error

func (BlackHole) Read Uses

func (BlackHole) Read(p []byte) (int, error)

func (BlackHole) Write Uses

func (BlackHole) Write(p []byte) (int, error)

type RefCount Uses

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

A Refcount can be embedded in structures to provide reference-counting of resources.

Code:

package main

import "aqwari.net/net/styx/internal/util"

type Session struct {
    util.RefCount
    User, Tree string
    Requests   chan []byte
}

func (s *Session) end() {
    select {
    case <-s.Requests:
        return
    }
    println("ending session")
    close(s.Requests)
}

func main() {
    s := &Session{Requests: make(chan []byte)}
    for i := 0; i < 10; i++ {
        s.IncRef()
    }

    for i := 0; i < 20; i++ {
        if !s.DecRef() {
            s.end()
            break
        }
    }
}

func (*RefCount) DecRef Uses

func (r *RefCount) DecRef() (remaining bool)

DecRef decrements refcount by 1. If the reference count has reached 0, DecRef will return false.

func (*RefCount) IncRef Uses

func (r *RefCount) IncRef()

IncRef increments refcount by 1. It is a run-time panic to create more than ^uint64(0) references.

type SectionWriter Uses

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

Section writer provides a partial analogue io.SectionReader, for writers.

func NewSectionWriter Uses

func NewSectionWriter(w io.WriterAt, off, n int64) *SectionWriter

func (*SectionWriter) Write Uses

func (s *SectionWriter) Write(p []byte) (int, error)

Package util imports 3 packages (graph) and is imported by 3 packages. Updated 2018-05-02. Refresh now. Tools for package owners.