github.com/blend/go-sdk@v1.20220411.3/examples/async/main.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package main 9 10 import ( 11 "context" 12 "fmt" 13 "runtime" 14 15 "github.com/blend/go-sdk/async" 16 ) 17 18 // WorkSize is the amount of work to do. 19 const WorkSize = 1 << 18 20 21 func main() { 22 work := make(chan interface{}, WorkSize) 23 24 for x := 0; x < WorkSize; x++ { 25 work <- fmt.Sprintf("work-%d", x) 26 } 27 28 batch := async.NewBatch(work, func(ctx context.Context, work interface{}) error { 29 fmt.Printf("%v\n", work) 30 return nil 31 }, async.OptBatchParallelism(runtime.NumCPU())) 32 33 batch.Process(context.TODO()) 34 }