Comments about Async/Await in Golang: An Introductory Guide

Correct me if I’m wrong

AFAIK the async await of C# is mostly (99%) for marking I/O related operations (access storage, network..) as asynchronous operations, but rarely for computation or Businesses Logic.

Go don’t need that because all I/O operations in Go is asynchronous by default.. In other words, all functions in Go is already Async Await.. (so you don’t need these keywords).

Create multiple go routines to access database or files are unnecessary.

You uses go routines, channel.. only if you wish to do computational logic asynchronously. And this is a rare use cases.. => justify for yourself while you would do that?

😊+

0 0

1 year ago

package main

import (
 "context"
 "fmt"
 "github.com/yaitoo/async"
)

func main() {
  t := async.New[int](func(ctx context.Context) (int, error) {
          return 1, nil
       }, func(ctx context.Context) (int, error) {
          return 2, nil
      })
 result, err := t.Wait(context.Background())

 if err == nil {
	fmt.Println(result) //[1,2]
  } else {
 	fmt.Println(err)
  }
 }

😊+

0 0

3 years ago

Question, how would I go about extending this function so that I can pass methods that return values?

😊+

0 1

Trending Topics

blockchaincryptocurrencyhackernoon-top-storyprogrammingsoftware-developmenttechnologystartuphackernoon-booksBitcoinbooks