util

package
v0.0.0-...-bf55d75 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package util contains internal routines used by the styx packages.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTempErr

func IsTempErr(err error) bool

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

Types

type BlackHole

type BlackHole struct{}

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

func (BlackHole) Close

func (BlackHole) Close() error

func (BlackHole) Read

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

func (BlackHole) Write

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

type RefCount

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

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

Example
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
	}
}

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
		}
	}
}
Output:

func (*RefCount) DecRef

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

func (r *RefCount) IncRef()

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

type SectionWriter

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

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

func NewSectionWriter

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

func (*SectionWriter) Write

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL