useraction

package
v0.24.6 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: BSD-3-Clause Imports: 7 Imported by: 1

Documentation

Overview

Package useraction: handle long running actions initiated from the browser. For example, selecting a file to open. POST returns a token and value if the request times out before a valid value is available the client can poll via GET passing the token until the requested value becomes available.

Index

Constants

View Source
const Expiry = 1 * time.Second

max time between an initial request and the attempt to get its results. needed so that unrequested results dont take up memory; shorter seems better.

View Source
const Timeout = 120 * time.Second

approximate amount of time an http request should wait to fulfill an action. note: chrome and firefox are both 300 seconds ( 5 minutes )

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatch

type Dispatch func(action string) (string, error)

uaRequest to start a new named action. Launched from a go routine, assumed to be blocking so that there's only dispatched action running at a time. For now: no parameters, and only a single string return ( ex. a filename )

type Dispatcher

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

func Start

func Start(dispatch Dispatch) *Dispatcher

returns a Dispatcher that can be used by multiple http handlers if need be. rus a go routine internally

func (*Dispatcher) Get

func (m *Dispatcher) Get(token Token) (ret string, err error)

given a token returned by post, see if the result is ready. err might be an http Status, or some error from the dispatcher. StatusuaRequestTimeout means the caller should try again.

func (*Dispatcher) Post

func (m *Dispatcher) Post(action string) (ret Result, err error)

request that the dispatch function specified in Start() process the requested action as soon as it can; returns a valid Token if the action is still pending or in progress after some timeout. err might be an http Status, or some error from the dispatcher.

type Pending

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

type Reader

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

http endpoints get results from readers.

func MakeReader

func MakeReader(res chan Pending) Reader

result channel could be small, probably size 1 result: make(chan result, 3),

func (*Reader) Read

func (r *Reader) Read(token Token) (string, error)

can be called by multiple http response handlers the result's token will match the passed token

type Result

type Result struct {
	Token Token
	Value string
}

only one of token or value gets set; indicated by whether Token.Valid() is true

type Token

type Token struct {
	Id, Time uint64
}

func MakeToken

func MakeToken() (ret Token)

ignores any parsing errors and returns an empty token

func ReadToken

func ReadToken(s string) (ret Token)

ignores any parsing errors and returns an empty token

func (*Token) String

func (t *Token) String() string

func (*Token) Valid

func (t *Token) Valid() bool

Jump to

Keyboard shortcuts

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