package promise

import "github.com/hack-pad/go-indexeddb/idb/internal/promise"

Package promise provides JavaScript Promise-like implementations

Index

Functions

func NewChan

func NewChan(ctx context.Context) (resolve, reject Resolver, promise Chan)

NewChan creates a new Chan

Types

type Chan

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

Chan is a Go channel-based promise

func (Chan) Await

func (c Chan) Await() (interface{}, error)

Await implements Promise

func (Chan) Catch

func (c Chan) Catch(fn func(rejectedReason interface{}) interface{}) Promise

Catch implements Promise

func (Chan) Then

func (c Chan) Then(fn func(value interface{}) interface{}) Promise

Then implements Promise

type Promise

type Promise interface {
	Then(fn func(value interface{}) interface{}) Promise
	Catch(fn func(value interface{}) interface{}) Promise
	Await() (interface{}, error)
}

Promise is a JS-like promise interface. Enables alternative implementations, like Go channels.

type Resolver

type Resolver func(interface{})

Resolver can be returned from a new Promise constructor, great for resolving successes and failures with values.

Source Files

chan.go promise.go

Version
v0.3.0
Published
Jan 18, 2023
Platform
js/wasm
Imports
2 packages
Last checked
4 hours ago

Tools for package owners.