Code Monkey home page Code Monkey logo

dag-1's Introduction

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

dag-1's People

Contributors

mostafa-asg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.