File tree Expand file tree Collapse file tree 5 files changed +77
-1
lines changed Expand file tree Collapse file tree 5 files changed +77
-1
lines changed Original file line number Diff line number Diff line change 1010
1111# Output of the go coverage tool, specifically when used with LiteIDE
1212* .out
13+
14+ # editors
15+ .idea
16+ .DS_Store
17+ .vscode
Original file line number Diff line number Diff line change 11MIT License
22
3- Copyright (c) 2019 Go Lang | REST Services
3+ Copyright (c) 2019 Roshan Gade
44
55Permission is hereby granted, free of charge, to any person obtaining a copy
66of this software and associated documentation files (the "Software"), to deal
Original file line number Diff line number Diff line change 11# async
22Perform multiple asynchronous tasks concurrently.
3+
4+
5+ # INCOMPLETE
6+ Working on it
Original file line number Diff line number Diff line change 1+ /*!
2+ * go-rs/async
3+ * Copyright(c) 2019 Roshan Gade
4+ * MIT Licensed
5+ */
6+ package async
7+
8+ type Task func () interface {}
9+ type Result chan interface {}
10+
11+ type Promise struct {
12+ //TODO:
13+ //Context - Cancel, Timeout
14+ //Concurrency vs Parallelism
15+ //What to do on error? Is it best way to abort all operation?
16+ }
17+
18+ func (p * Promise ) All (tasks []Task ) []Result {
19+ workers := make ([]Result , 0 , len (tasks ))
20+ for _ , task := range tasks {
21+ result := execute (task )
22+ workers = append (workers , result )
23+ }
24+ return workers
25+ }
26+
27+ func execute (task Task ) Result {
28+ out := make (Result )
29+ {
30+ go func () {
31+ defer close (out )
32+ out <- task ()
33+ }()
34+ }
35+ return out
36+ }
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "fmt"
5+ "time"
6+
7+ "github.com/go-rs/async"
8+ )
9+
10+ func main () {
11+ fmt .Println ("start" )
12+ var promise async.Promise
13+
14+ tasks := []async.Task {
15+ func () interface {} {
16+ time .Sleep (1000 * time .Microsecond )
17+ return "Hello"
18+ },
19+ func () interface {} {
20+ time .Sleep (100 * time .Microsecond )
21+ return "World"
22+ },
23+ }
24+
25+ for _ , a := range promise .All (tasks ) {
26+ // switch statement for results
27+ fmt .Println (<- a )
28+ }
29+
30+ fmt .Println ("exit" )
31+ }
You can’t perform that action at this time.
0 commit comments