putil

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2020 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-promise-util

promise util for go

Build Status Coverage Status GoDoc Go Report Card PRs Welcome

Install

$ go get gopkg.in/magicdawn/go-promise-util

API

package name = putil

use

putil.Map()
putil.Async()
putil.AsyncFactory()
Map
Map(
  items interface{}[],
  fn func(item interface{}, index int, items []interface{}) *promise.Promise,
  concurrency int
) *promise.Promise

like node.js promise.map / async.parallelLimit

Async & AsyncFactory
sleepUseNewPromise := func(sec int) *promise.Promise {
  return promise.New(func(resolve func(interface{}), reject func(error)) {
    time.Sleep(time.Second * time.Duration(sec))
    resolve(sec * sec)
  })
}

sleepUseAsync := func(sec int) *promise.Promise {
  return promiseUtil.Async(func() interface{} {
    time.Sleep(time.Second * time.Duration(sec))
    return sec
  })
}

sleepUseAsyncFactory := promiseUtil.AsyncFactory(func(args ...interface{}) interface{} {
  sec := args[0].(int)
  time.Sleep(time.Second * time.Duration(sec))
  return sec
})

Changelog

CHANGELOG.md

License

the MIT License http://magicdawn.mit-license.org

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Async

func Async(fn func() interface{}) *promise.Promise

Async: wrap a func & use fn's return value to resolve, like `co()`

func AsyncFactory

func AsyncFactory(fn func(args ...interface{}) interface{}) func(args ...interface{}) *promise.Promise

AsyncFactory: create a async function, like `co.wrap`

func Map

func Map(
	items []interface{},
	fn func(interface{}, int, []interface{}) *promise.Promise,
	concurrency int) *promise.Promise

Map: Map items to Promise with concurrency

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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