Coder Social home page Coder Social logo

nasync's Introduction

NASYNC

a customizable async task pool for golang, (event bus, runtime)

Fetures

  • less memory
  • more effective
  • max gorutines and memory customizable
  • more safe

Simple Usage

nasync.Do(function)

Async Http Client

http.DefaultTransport.(*http.Transport).MaxIdleConns = 2000
http.DefaultTransport.(*http.Transport).MaxIdleConnsPerHost = 1000
	
nasync.Do(func() {
    resp, err := http.Get("http://example.com")
    if err == nil {
        io.Copy(ioutil.Discard, resp.Body)
        resp.Body.Close()
    }
})

Advanced Usage

go get github.com/ti/nasync
import "github.com/ti/nasync"

func main() {
        //new a async pool in max 1000 task in max 1000 gorutines
        async := nasync.New(1000,1000)
        defer async.Close()
        async.Do(doSometing,"hello word")
}


func doSometing(msg string) string{
	return "i am done by " + msg
}

WHY

golang is something easy but fallible language, you may do this

   func yourfucntion() {
            go dosomething()  // this will got error on high load
    }

you may get "too many open files" error, when your application in High load, so you need this, you can do any thing in async by this, it is trusty。your can use this for:

  • http or file writer logging
  • improve main thread speed
  • limited background task pool

What if something callback ?

import "github.com/ti/nasync"

func main() {
        nasync.Do(func() {
        		result := doSometing("msg")
        		fmt.Println("i am call back by ",result)
        })
}

func doSometing(msg string) string{
	return "i am done by " + msg
}

nasync's People

Contributors

leenanxi avatar ti avatar tiupcn 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.