• Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
    Go
  • License
    The Unlicense
  • Created almost 7 years ago
  • Updated about 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple DSL for executing functions in Go

dag has two main concept:

  1. Pipeline executes the functions sequentially and in order.
  2. Spawns executes the functions concurrently, so there is no ordering guarantee.

Example 1

example1

d := dag.New()
d.Pipeline(f1, f2, f3)
d.Run()

In the above example, f1 starts first, and after completion, f2 starts then f3.
Full example : examples/ex1/ex1.go

Example 2

example2

d := dag.New()
d.Spawns(f1, f2, f3)
d.Run()

The order of execution of f1, f2 and f3 is nondeterministic
Full example : examples/ex2/ex2.go

Example 3

example3
In this example f4 must be executed after complition of f1, f2 and f3. You can use Join method:

d := dag.New()
d.Spawns(f1, f2, f3).Join().Pipeline(f4)
d.Run()

Full example : examples/ex3/ex3.go

Example 4

example4
After pipeline we can use Then method:

d := dag.New()
d.Pipeline(f1, f2, f3).Then().Spawns(f4, f5, f6)
d.Run()

Full example : examples/ex4/ex4.go

Example 5

example5

d := dag.New()
d.Spawns(f1, f2, f3).
	Join().
	Pipeline(f4, f5).
	Then().
	Spawns(f6, f7, f8)
d.Run()

Full example : examples/ex5/ex5.go

Example 6

example6
We want to execute two pipeline concrrently, we can use pipeline.Of inside the Spawns method:

d := dag.New()
d.Spawns(pipeline.Of(f1, f3), pipeline.Of(f2, f4)).
	Join().
	Pipeline(f5)
d.Run()

Full example : examples/ex6/ex6.go

Example 7

We can use OnComplete method after Pipeline or Spawns to notify when functions has completed.

d := dag.New()
d.Pipeline(f1, f2).OnComplete(f3).
	  Then().
  Spawns(f1, f2).OnComplete(f4)
d.Run()

Full example : examples/ex7/ex7.go

Example 8

Basically, Run() will block until all functions are done. If you don't want to be blocked, you can use RunAsync() method. It accepts a callback function, that will be called when all functions are done.

d := dag.New()
d.Pipeline(f1, f2).Then().Spawns(f3, f4)
d.RunAsync(onComplete)

Full example : examples/ex8/ex8.go

More Repositories

1

go-dl

Dead simple file downloader in Go
Go
40
star
2

SpellChecker

Spell checker written in Kotlin
Kotlin
4
star
3

tickets4sale

Functional programming practice in Scala. Information about project ->
Scala
4
star
4

lag

Fun way to see Kafka lag
Go
3
star
5

DemoAkkaHttp

Demo - RESTful api for manipulating users based on Akka Http and Slick
Scala
3
star
6

retry

Don't give up, at least at first attempt!
Kotlin
3
star
7

bolbol

Learn languages on terminal, by short and practical sentences.
JavaScript
3
star
8

bit

Bitset implementation in Go
Go
2
star
9

pelican

Embedable/Standalone In-memory Key Value Store, suitable for single-machine applications.
Go
2
star
10

ip2country

Fast IPv4 to country lookup
Go
2
star
11

Scala99Problems

My Solutions to Ninety-Nine Scala Problems
Scala
1
star
12

fullstack

1
star
13

git-cont-act

Draw Github's contribution activity
Go
1
star
14

mostafa-asg

1
star
15

race

🏁 Race between http requests
Go
1
star
16

gobreaker

Circuit Breaker implemented in Go
Go
1
star
17

Avro-RPC-Sample

Simple Avro RPC implementation
Java
1
star
18

lru

Thread-safe LRU Cache
Go
1
star
19

mostafa-asg.github.io

Static contents of my personal blog
HTML
1
star
20

tweet-sentiment

Naive Bayes Tweet Sentiment Classifier
Python
1
star
21

Algo

Python
1
star
22

hugo

contents of Hugo site generator for my personal website
1
star
23

einstein

Do not memorize commands. Copy and Paste them :)
1
star
24

KStreams

Demo application to reactively calculate top 5 high scores of users (ex. game users) using Kafka Streams and send results to the clients using SSE
Java
1
star
25

awesome-articles

A curated list of awesome articles and tutorials that I 've found interesting
1
star