storedcounter

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: Apache-2.0, MIT Imports: 5 Imported by: 0

README

go-storedcounter

A simple thread safe persisted counter

Table of Contents

Description

The module provides a simple counter on top of a go-ipfs-datastore interface

Install

go get github.com/filecoin-project/go-storedcounter

Usage

Create/load a counter for a datastore and key:

import(
  "github.com/ipfs/go-datastore"
  "github.com/filecoin-project/go-storedcounter"
)

var ds datastore.Datastore
var name datastore.Key

storedCounter := storedcounter.New(ds, name)

Get the next value (will start at 0):

next := storedcCounter.Next()

License

Dual-licensed under MIT + Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StoredCounter

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

StoredCounter is a counter that persists to a datastore as it increments

func New

func New(ds datastore.Datastore, name datastore.Key) *StoredCounter

New returns a new StoredCounter for the given datastore and key

func (*StoredCounter) Get

func (sc *StoredCounter) Get() (uint64, error)

Get Added in 2021-12-15, Get current sector number

func (*StoredCounter) Next

func (sc *StoredCounter) Next() (uint64, error)

Next returns the next counter value, updating it on disk in the process if no counter is present, it creates one and returns a 0 value

func (*StoredCounter) Set

func (sc *StoredCounter) Set(sectorNum uint64) error

Set Added in 2021-12-15, Set the next sector number

Jump to

Keyboard shortcuts

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