File: async.go

package info (click to toggle)
golang-github-evilsocket-islazy 1.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 292 kB
  • sloc: javascript: 8; makefile: 3
file content (31 lines) | stat: -rw-r--r-- 484 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main

import (
	"fmt"
	"time"

	"github.com/evilsocket/islazy/async"
)

func main() {
	// timed calls
	_, err := async.WithTimeout(1*time.Second, func() interface{} {
		// this will timeout
		time.Sleep(5 * time.Second)
		return nil
	})
	if err != nil {
		fmt.Printf("%s\n", err)
	}

	// -1/0 = use all logical CPUs
	q := async.NewQueue(0, func(arg async.Job) {
		fmt.Printf("got job %d\n", arg.(int))
	})

	for i := 0; i < 10; i++ {
		q.Add(async.Job(i))
	}

	q.WaitDone()
}