task

package
v0.0.0-...-1f40f5c Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2024 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Example
package main

import (
	"fmt"
	"time"

	"codeberg.org/FedericoSchonborn/go-sandbox/task"
)

func main() {
	waitOneSecondAndReturnFive := func() int {
		time.Sleep(1 * time.Second)
		return 5
	}

	fmt.Println(task.New(waitOneSecondAndReturnFive).Join())
}
Output:

5

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Join

func Join[T any](handles ...*Handle[T]) []T
Example
package main

import (
	"fmt"
	"math/rand"
	"time"

	"codeberg.org/FedericoSchonborn/go-sandbox/task"
)

func main() {
	rand.Seed(time.Now().Unix())
	returnSix := func() int {
		return 6
	}

	handles := make([]*task.Handle[int], 10)
	for i := 0; i < 10; i++ {
		handles[i] = task.New(returnSix)
	}

	fmt.Println(task.Join(handles...))
}
Output:

[6 6 6 6 6 6 6 6 6 6]

Types

type Handle

type Handle[T any] struct {
	// contains filtered or unexported fields
}

func New

func New[T any](fn func() T) *Handle[T]

func (*Handle[T]) Join

func (h *Handle[T]) Join() T

Jump to

Keyboard shortcuts

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