peertask

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: May 10, 2019 License: Apache-2.0, MIT Imports: 3 Imported by: 16

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FIFOCompare = func(a, b *TaskBlock) 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 *TaskBlock) 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 *TaskBlock) bool) func(a, b pq.Elem) bool

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

Types

type Identifier

type Identifier interface{}

Identifier is a unique identifier for a task. It's used by the client library to act on a task once it exits the queue.

type Task

type Task struct {
	Identifier Identifier
	Priority   int
}

Task is a single task to be executed as part of a task block.

type TaskBlock

type TaskBlock struct {
	Tasks    []Task
	Priority int
	Target   peer.ID

	// A callback to signal that this task block has been completed
	Done func([]Task)
	// contains filtered or unexported fields
}

TaskBlock is a block of tasks to execute on a single peer.

func NewTaskBlock

func NewTaskBlock(tasks []Task, priority int, target peer.ID, done func([]Task)) *TaskBlock

NewTaskBlock creates a new task block with the given tasks, priority, target peer, and task completion function.

func (*TaskBlock) Index

func (pt *TaskBlock) Index() int

Index implements pq.Elem.

func (*TaskBlock) MarkPrunable

func (pt *TaskBlock) MarkPrunable(identifier Identifier)

MarkPrunable marks any tasks with the given identifier as prunable at the time the task block is pulled of the queue to execute (because they've already been removed).

func (*TaskBlock) PruneTasks

func (pt *TaskBlock) PruneTasks()

PruneTasks removes all tasks previously marked as prunable from the lists of tasks in the block

func (*TaskBlock) SetIndex

func (pt *TaskBlock) SetIndex(i int)

SetIndex implements pq.Elem.

Jump to

Keyboard shortcuts

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