promise

package
v0.0.0-...-bcea9b7 Latest Latest
Warning

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

Go to latest
Published: May 10, 2021 License: MIT Imports: 3 Imported by: 0

README

Usage

promise.Do comes with a very primitive way of callback dispatch. It immediately executes the callback, instead of scheduling it for execution

Example

package main 

import (
	"github.com/donutloop/toolkit/promise"
	"log"
)

func main() {
	done, errc := promise.Do(context.Background(), func(ctx context.Context) error {
		// do things
		return nil
	})

	select {
	case <-done:
	case err := <-errc:
		if err != nil {
			log.Fatal(err)
		}
	}
}

Documentation

Overview

Example
package main

import (
	"context"
	"fmt"

	"github.com/donutloop/toolkit/promise"
)

func main() {
	done, errc := promise.Do(context.Background(), func(ctx context.Context) error {
		fmt.Println("do things")
		return nil
	})

	select {
	case <-done:
	case err := <-errc:
		fmt.Printf("error: %v \n", err)
	}

}
Output:

do things

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, f func(ctx context.Context) error) (<-chan struct{}, chan error)

Do is a basic promise implementation: it wraps calls a function in a goroutine.

Types

type RecoverError

type RecoverError struct {
	Err   interface{}
	Stack []byte
}

func (*RecoverError) Error

func (e *RecoverError) Error() string

Jump to

Keyboard shortcuts

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