Giter Club home page Giter Club logo

depfunc's Introduction

depfunc

depfunc is a package that enables concurrent resolution of dependent actions.

Image you have a network of actions that should be evaluated, by this depends on that, and that depends on another.

This package allows the construction of such a graph and a way to evaluate the result.

Motivation

It seemed like a good idea at the time.

Applesauce

Imagine applesauce.

To produce applesauce, you need apples, sugar, and a can. To make a can, you need metal. You also might want to perform some kind of QA on the canning process.

Your manufacturing process may look something like this:


 | [apples]   [sugar]   [metal]
 |      \       /         /
 |       \     /         /
 |        \   /   [qa] [can]
 |         \  \    /  /
 โ†“          [applesauce]

You could create your graph like this:

graph := depfunc.NewGraph()

graph.AddAction("apples", growApples)
graph.AddAction("sugars", growSugar)
graph.AddAction("metals", recycleMetal)
graph.AddAction("cans", formCans)
graph.AddAction("applesauce", canApplesauce)
graph.AddAction("qa", qa)

graph.LinkDependency("metals", "cans")
graph.LinkDependency("cans", "applesauce")

graph.LinkDependency("apples", "applesauce")
graph.LinkDependency("sugars", "applesauce")
graph.LinkDependency("qa", "applesauce")

Great! Now every season you can run it like so:

ctx, err := graph.Resolve(context.Background(), &factory{})
checkError(err)
select {
 <-ctx.Done():
 	fmt.Println("Hooray! Applesauce!")
}

And your factory will be full of various products.

Cool, but how long did it take?

stats := depfunc.NewStatistics()

graph.Resolve(context.Background(), &factory{}, stats.Recorder())
checkError(err)
select {
 <-ctx.Done():
 	fmt.Printf("Hooray! Applesauce! Applesauce waited %v to produce, and took %v to actual can it up.\n", stats.Wait(), stats.Action())
}
// prints: Hooray! Applesauce! Applesauce waited 337.254578ms to produce, and took 312.194456ms to actual can it up.

depfunc's People

Contributors

explodes avatar

Stargazers

 avatar

Watchers

 avatar  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.