peertask

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2021 License: MIT, Apache-2.0, MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FIFOCompare = func(a, b *QueueTask) bool {
	return a.created.Before(b.created)
}

FIFOCompare is a basic task comparator that returns tasks in the order created.

View Source
var PriorityCompare = func(a, b *QueueTask) bool {
	if a.Target == b.Target {
		return a.Priority > b.Priority
	}
	return FIFOCompare(a, b)
}

PriorityCompare respects the target peer's task priority. For tasks involving different peers, the oldest task is prioritized.

Functions

func WrapCompare

func WrapCompare(f func(a, b *QueueTask) bool) func(a, b pq.Elem) bool

WrapCompare wraps a QueueTask comparison function so it can be used as comparison for a priority queue

Types

type Data

type Data interface{}

Data is used by the client to associate extra information with a Task

type QueueTask

type QueueTask struct {
	Task
	Target peer.ID
	// contains filtered or unexported fields
}

QueueTask contains a Task, and also some bookkeeping information. It is used internally by the PeerTracker to keep track of tasks.

func NewQueueTask

func NewQueueTask(task Task, target peer.ID, created time.Time) *QueueTask

NewQueueTask creates a new QueueTask from the given Task.

func (*QueueTask) Index

func (pt *QueueTask) Index() int

Index implements pq.Elem.

func (*QueueTask) SetIndex

func (pt *QueueTask) SetIndex(i int)

SetIndex implements pq.Elem.

type Task

type Task struct {
	// Topic for the task
	Topic Topic
	// Priority of the task
	Priority int
	// The size of the task
	// - peers with most active work are deprioritized
	// - peers with most pending work are prioritized
	Work int
	// Arbitrary data associated with this Task by the client
	Data Data
}

Task is a single task to be executed in Priority order.

type Topic

type Topic interface{}

Topic is a non-unique name for a task. It's used by the client library to act on a task once it exits the queue.

Jump to

Keyboard shortcuts

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