Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/magicdawn/go-promise-util
extra util for golang promise
https://github.com/magicdawn/go-promise-util
async go-promise go-promise-util promise promise-map
Last synced: about 1 month ago
JSON representation
extra util for golang promise
- Host: GitHub
- URL: https://github.com/magicdawn/go-promise-util
- Owner: magicdawn
- License: mit
- Created: 2020-03-10T14:26:53.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-03-11T05:32:22.000Z (over 4 years ago)
- Last Synced: 2024-06-20T13:38:44.129Z (5 months ago)
- Topics: async, go-promise, go-promise-util, promise, promise-map
- Language: Go
- Size: 15.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# go-promise-util
> promise util for go
[![Build Status](https://img.shields.io/travis/magicdawn/go-promise-util.svg?style=flat-square)](https://travis-ci.org/magicdawn/go-promise-util)
[![Coverage Status](https://img.shields.io/codecov/c/github/magicdawn/go-promise-util.svg?style=flat-square)](https://codecov.io/gh/magicdawn/go-promise-util)
[![GoDoc](https://img.shields.io/badge/godoc-reference-brightgreen?style=flat-square)](https://godoc.org/github.com/magicdawn/go-promise-util)
[![Go Report Card](https://goreportcard.com/badge/github.com/magicdawn/go-promise-util?style=flat-square)](https://goreportcard.com/report/github.com/magicdawn/go-promise-util)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)## Install
```sh
$ go get github.com/magicdawn/go-promise-util
```## API
### package name = putil
use
```go
putil.Map()
putil.Async()
putil.AsyncFactory()
```### Map
```go
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
```go
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](CHANGELOG.md)
## License
the MIT License http://magicdawn.mit-license.org