https://github.com/magicdawn/go-co
coroutine , async/await for golang
https://github.com/magicdawn/go-co
Last synced: about 1 year ago
JSON representation
coroutine , async/await for golang
- Host: GitHub
- URL: https://github.com/magicdawn/go-co
- Owner: magicdawn
- Created: 2015-05-09T12:18:10.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2020-03-06T14:44:38.000Z (over 6 years ago)
- Last Synced: 2025-03-30T22:32:10.562Z (over 1 year ago)
- Language: Go
- Homepage:
- Size: 22.5 KB
- Stars: 21
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# go-co
[](https://godoc.org/github.com/magicdawn/go-co)
coroutine , async/await for golang
## Goals
to simulate
- yield/Promise in node.js, [co](https://github.com/tj/co)
- async/await/Task in C#
*checkout blog http://magicdawn.ml/2015/01/10/generator-and-promise/*
## Install
with [glide](https://github.com/Masterminds/glide)
```sh
$ glide get github.com/magicdawn/go-co
```
## API
### `co`
```go
import "github.com/magicdawn/go-co"
```
- co.Task : similar to Task in .NET,stands for a samll piece of work
- co.Await: await a Task
```go
result,err := co.Await(task)
```
- co.Async: make a Task
```go
func sleep() *co.Task{
return co.Async(func() interface{}{
time.sleep(time.Seconds * 10)
return nil
})
}
```
here is a Task will need 10 seconds
### `coutil`
- `coutil.Each` : like `Promise.each`
- `coutil.Map` : like `Promise.map` with concurrency support
*more checkout demo/ directory*
## CHANGELOG
[CHANGELOG.md](CHANGELOG.md)
## License
the MIT license (magicdawn@qq.com)