Giter Site home page Giter Site logo

goconcurrenct's Introduction

Requirement

2 important requirements which impact the design a lot

Half sync and half async.

This is important for request processing. For example: In STG, the workload is small, a receivable creation request can be done with seconds, to return the result in response is very friendly to the engineer. But in production, the data is big, it will takes over 1 hours sometimes, the endpoint can't wait infinitely, alternative return a requestID in response and let the engineer to check the Kibana log.

Parent goroutine need to know all the details of child goroutine

  • The child goroutine returned an error, parent goroutine can return an reasonable error
  • There is a panic in child goroutine, the parent goroutine can catch it and return an error
  • The child can run in Async mode after the wait for some time, then this request become an async call, return the requestID
  • The parent goroutine is canceled by synchronize control

the API design should be closure return an error, or even more data

backgroundFunc = func() error {
  // do something
  if err {
    return err
  }
  return nil
}

retErr := goWithRecovery(ctx, backgroundFunc, timeout)

// or return a value
backgroundFuncWithResult = func() (interface{}, error) {
}

Parent goroutine can control child goroutine

For example: you are running data deletion from RDS periodly, If previous goroutine is still running, then new goroutine will compete with old one. This control generall is controld by context.

backgroundFunc = func() error {
  nexCtx = context.WithTimeout(context.Background(), duration)
  // do something with newCtx
  if err {
    return err
  }
  return nil
}

Other consideration

Dependencies

When you implement it in your company, it is criticial to make it as simple as possible to simple integration. 2 main considerations is DdataDog, Logging

So the best way is to add a more layer to integrate it with different dependencies

goconcurrenct's People

Contributors

yang-rongquan avatar jacky098123 avatar

Watchers

 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.