[{"data":1,"prerenderedAt":1371},["ShallowReactive",2],{"navigation_docs":3,"-advanced-go-advanced-concurrency":377,"-advanced-go-advanced-concurrency-surround":1366},[4,39,114,144,184,244,293,362],{"title":5,"icon":6,"path":7,"stem":8,"children":9,"page":6},"Getting Started",false,"\u002Fgetting-started","1.getting-started",[10,15,20,25,30,35],{"title":11,"path":12,"stem":13,"icon":14},"Learning Path","\u002Fgetting-started\u002Flearning-path","1.getting-started\u002F1.learning-path","i-lucide-map",{"title":16,"path":17,"stem":18,"icon":19},"Introduction","\u002Fgetting-started\u002Fintroduction","1.getting-started\u002F2.introduction","i-lucide-house",{"title":21,"path":22,"stem":23,"icon":24},"Installation","\u002Fgetting-started\u002Finstallation","1.getting-started\u002F3.installation","i-lucide-download",{"title":26,"path":27,"stem":28,"icon":29},"Your First Program","\u002Fgetting-started\u002Ffirst-program","1.getting-started\u002F4.first-program","i-lucide-play",{"title":31,"path":32,"stem":33,"icon":34},"Modules and Dependencies","\u002Fgetting-started\u002Fmodules-and-dependencies","1.getting-started\u002F5.modules-and-dependencies","i-lucide-package-open",{"title":36,"path":37,"stem":38,"icon":34},"Advanced Modules","\u002Fgetting-started\u002Fadvanced-modules","1.getting-started\u002F6.advanced-modules",{"title":40,"path":41,"stem":42,"children":43,"page":6},"Fundamentals","\u002Ffundamentals","2.fundamentals",[44,49,54,59,64,69,74,79,84,89,94,99,104,109],{"title":45,"path":46,"stem":47,"icon":48},"Program Structure","\u002Ffundamentals\u002Fprogram-structure","2.fundamentals\u002F1.program-structure","i-lucide-workflow",{"title":50,"path":51,"stem":52,"icon":53},"Structs and Methods","\u002Ffundamentals\u002Fstructs-and-methods","2.fundamentals\u002F10.structs-and-methods","i-lucide-box",{"title":55,"path":56,"stem":57,"icon":58},"Interfaces","\u002Ffundamentals\u002Finterfaces","2.fundamentals\u002F11.interfaces","i-lucide-plug",{"title":60,"path":61,"stem":62,"icon":63},"Error Handling","\u002Ffundamentals\u002Ferrors","2.fundamentals\u002F12.errors","i-lucide-triangle-alert",{"title":65,"path":66,"stem":67,"icon":68},"Defined Types and Type Aliases","\u002Ffundamentals\u002Fdefined-types","2.fundamentals\u002F13.defined-types","i-lucide-tags",{"title":70,"path":71,"stem":72,"icon":73},"Generics","\u002Ffundamentals\u002Fgenerics","2.fundamentals\u002F14.generics","i-lucide-blocks",{"title":75,"path":76,"stem":77,"icon":78},"Project Structure","\u002Ffundamentals\u002Fproject-structure","2.fundamentals\u002F2.project-structure","i-lucide-folder-tree",{"title":80,"path":81,"stem":82,"icon":83},"Project Layout","\u002Ffundamentals\u002Fproject-layout","2.fundamentals\u002F3.project-layout","i-lucide-layout",{"title":85,"path":86,"stem":87,"icon":88},"Variables and Data Types","\u002Ffundamentals\u002Fvariables-and-types","2.fundamentals\u002F4.variables-and-types","i-lucide-variable",{"title":90,"path":91,"stem":92,"icon":93},"Functions","\u002Ffundamentals\u002Ffunctions","2.fundamentals\u002F5.functions","i-lucide-braces",{"title":95,"path":96,"stem":97,"icon":98},"Control Statements","\u002Ffundamentals\u002Fcontrol-statements","2.fundamentals\u002F6.control-statements","i-lucide-git-branch",{"title":100,"path":101,"stem":102,"icon":103},"Pointers","\u002Ffundamentals\u002Fpointers","2.fundamentals\u002F7.pointers","i-lucide-mouse-pointer-2",{"title":105,"path":106,"stem":107,"icon":108},"Arrays and Slices","\u002Ffundamentals\u002Farrays-and-slices","2.fundamentals\u002F8.arrays-and-slices","i-lucide-list",{"title":110,"path":111,"stem":112,"icon":113},"Maps","\u002Ffundamentals\u002Fmaps","2.fundamentals\u002F9.maps","i-lucide-table-properties",{"title":115,"path":116,"stem":117,"children":118,"page":6},"Concurrency","\u002Fconcurrency","3.concurrency",[119,124,129,134,139],{"title":120,"path":121,"stem":122,"icon":123},"Concurrency Model","\u002Fconcurrency\u002Fconcurrency-model","3.concurrency\u002F1.concurrency-model","i-lucide-network",{"title":125,"path":126,"stem":127,"icon":128},"Goroutines","\u002Fconcurrency\u002Fgoroutines","3.concurrency\u002F2.goroutines","i-lucide-git-fork",{"title":130,"path":131,"stem":132,"icon":133},"Channels","\u002Fconcurrency\u002Fchannels","3.concurrency\u002F3.channels","i-lucide-arrow-left-right",{"title":135,"path":136,"stem":137,"icon":138},"Select and Cancellation","\u002Fconcurrency\u002Fselect-and-cancellation","3.concurrency\u002F4.select-and-cancellation","i-lucide-circle-stop",{"title":140,"path":141,"stem":142,"icon":143},"Synchronization","\u002Fconcurrency\u002Fsynchronization","3.concurrency\u002F5.synchronization","i-lucide-lock-keyhole",{"title":145,"path":146,"stem":147,"children":148,"page":6},"Standard Library","\u002Fstandard-library","4.standard-library",[149,154,159,164,169,174,179],{"title":150,"path":151,"stem":152,"icon":153},"Standard Library Overview","\u002Fstandard-library\u002Foverview","4.standard-library\u002F1.overview","i-lucide-library",{"title":155,"path":156,"stem":157,"icon":158},"Text and Formatting","\u002Fstandard-library\u002Ftext-and-formatting","4.standard-library\u002F2.text-and-formatting","i-lucide-text",{"title":160,"path":161,"stem":162,"icon":163},"Files and JSON","\u002Fstandard-library\u002Ffiles-and-json","4.standard-library\u002F3.files-and-json","i-lucide-file-json",{"title":165,"path":166,"stem":167,"icon":168},"HTTP Clients and Servers","\u002Fstandard-library\u002Fhttp","4.standard-library\u002F4.http","i-lucide-server",{"title":170,"path":171,"stem":172,"icon":173},"Testing","\u002Fstandard-library\u002Ftesting","4.standard-library\u002F5.testing","i-lucide-flask-conical",{"title":175,"path":176,"stem":177,"icon":178},"Command-Line Tools and Configuration","\u002Fstandard-library\u002Fcommand-line-and-configuration","4.standard-library\u002F6.command-line-and-configuration","i-lucide-terminal-square",{"title":180,"path":181,"stem":182,"icon":183},"Structured Logging","\u002Fstandard-library\u002Fstructured-logging","4.standard-library\u002F7.structured-logging","i-lucide-scroll-text",{"title":185,"path":186,"stem":187,"children":188,"page":6},"Backend Development","\u002Fbackend-development","5.backend-development",[189,194,199,204,209,214,219,224,229,234,239],{"title":190,"path":191,"stem":192,"icon":193},"Backend Roadmap","\u002Fbackend-development\u002Fbackend-roadmap","5.backend-development\u002F1.backend-roadmap","i-lucide-route",{"title":195,"path":196,"stem":197,"icon":198},"Graceful Shutdown","\u002Fbackend-development\u002Fgraceful-shutdown","5.backend-development\u002F10.graceful-shutdown","i-lucide-power",{"title":200,"path":201,"stem":202,"icon":203},"Production Checklist","\u002Fbackend-development\u002Fproduction-checklist","5.backend-development\u002F11.production-checklist","i-lucide-clipboard-check",{"title":205,"path":206,"stem":207,"icon":208},"HTTP API Design","\u002Fbackend-development\u002Fhttp-api-design","5.backend-development\u002F2.http-api-design","i-lucide-waypoints",{"title":210,"path":211,"stem":212,"icon":213},"Middleware","\u002Fbackend-development\u002Fmiddleware","5.backend-development\u002F3.middleware","i-lucide-layers-3",{"title":215,"path":216,"stem":217,"icon":218},"Validation","\u002Fbackend-development\u002Fvalidation","5.backend-development\u002F4.validation","i-lucide-list-checks",{"title":220,"path":221,"stem":222,"icon":223},"Application Wiring","\u002Fbackend-development\u002Fapplication-wiring","5.backend-development\u002F5.application-wiring","i-lucide-cable",{"title":225,"path":226,"stem":227,"icon":228},"Observability","\u002Fbackend-development\u002Fobservability","5.backend-development\u002F6.observability","i-lucide-activity",{"title":230,"path":231,"stem":232,"icon":233},"Database SQL","\u002Fbackend-development\u002Fdatabase-sql","5.backend-development\u002F7.database-sql","i-lucide-database",{"title":235,"path":236,"stem":237,"icon":238},"Transactions","\u002Fbackend-development\u002Ftransactions","5.backend-development\u002F8.transactions","i-lucide-repeat-2",{"title":240,"path":241,"stem":242,"icon":243},"Authentication and Authorization","\u002Fbackend-development\u002Fauthentication","5.backend-development\u002F9.authentication","i-lucide-shield-check",{"title":245,"path":246,"stem":247,"children":248,"page":6},"Advanced Go","\u002Fadvanced-go","6.advanced-go",[249,254,259,264,269,274,278,283,288],{"title":250,"path":251,"stem":252,"icon":253},"Advanced Go Roadmap","\u002Fadvanced-go\u002Fadvanced-roadmap","6.advanced-go\u002F1.advanced-roadmap","i-lucide-brain-circuit",{"title":255,"path":256,"stem":257,"icon":258},"Reflection","\u002Fadvanced-go\u002Freflection","6.advanced-go\u002F2.reflection","i-lucide-scan-search",{"title":260,"path":261,"stem":262,"icon":263},"Memory and Garbage Collection","\u002Fadvanced-go\u002Fmemory-and-garbage-collection","6.advanced-go\u002F3.memory-and-garbage-collection","i-lucide-memory-stick",{"title":265,"path":266,"stem":267,"icon":268},"Benchmarking and Profiling","\u002Fadvanced-go\u002Fbenchmarking-and-profiling","6.advanced-go\u002F4.benchmarking-and-profiling","i-lucide-gauge",{"title":270,"path":271,"stem":272,"icon":273},"Advanced Testing and Fuzzing","\u002Fadvanced-go\u002Fadvanced-testing-and-fuzzing","6.advanced-go\u002F5.advanced-testing-and-fuzzing","i-lucide-microscope",{"title":275,"path":276,"stem":277,"icon":48},"Advanced Concurrency","\u002Fadvanced-go\u002Fadvanced-concurrency","6.advanced-go\u002F6.advanced-concurrency",{"title":279,"path":280,"stem":281,"icon":282},"Unsafe and C Boundaries","\u002Fadvanced-go\u002Funsafe-and-cgo","6.advanced-go\u002F7.unsafe-and-cgo","i-lucide-radiation",{"title":284,"path":285,"stem":286,"icon":287},"Package and API Design","\u002Fadvanced-go\u002Fpackage-and-api-design","6.advanced-go\u002F8.package-and-api-design","i-lucide-boxes",{"title":289,"path":290,"stem":291,"icon":292},"Distributed Reliability","\u002Fadvanced-go\u002Fdistributed-reliability","6.advanced-go\u002F9.distributed-reliability","i-lucide-cloud-cog",{"title":294,"path":295,"stem":296,"children":297,"page":6},"Projects","\u002Fprojects","7.projects",[298,316,332,347],{"title":299,"path":300,"stem":301,"children":302,"icon":305},"CLI Task Manager","\u002Fprojects\u002Fcli-task-manager","7.projects\u002F1.cli-task-manager\u002Findex",[303,306,311],{"title":304,"path":300,"stem":301,"icon":305},"Project — CLI Task Manager","i-lucide-list-todo",{"title":307,"path":308,"stem":309,"icon":310},"CLI — Domain and Storage","\u002Fprojects\u002Fcli-task-manager\u002Fdomain-and-storage","7.projects\u002F1.cli-task-manager\u002F1.domain-and-storage","i-lucide-save",{"title":312,"path":313,"stem":314,"icon":315},"CLI — Commands and Tests","\u002Fprojects\u002Fcli-task-manager\u002Fcommands-and-tests","7.projects\u002F1.cli-task-manager\u002F2.commands-and-tests","i-lucide-terminal",{"title":317,"path":318,"stem":319,"children":320,"icon":323},"Concurrent URL Checker","\u002Fprojects\u002Fconcurrent-url-checker","7.projects\u002F2.concurrent-url-checker\u002Findex",[321,324,328],{"title":322,"path":318,"stem":319,"icon":323},"Project — Concurrent URL Checker","i-lucide-radar",{"title":325,"path":326,"stem":327,"icon":128},"URL Checker — Worker Pipeline","\u002Fprojects\u002Fconcurrent-url-checker\u002Fworker-pipeline","7.projects\u002F2.concurrent-url-checker\u002F1.worker-pipeline",{"title":329,"path":330,"stem":331,"icon":173},"URL Checker — Cancellation and Tests","\u002Fprojects\u002Fconcurrent-url-checker\u002Fcancellation-and-tests","7.projects\u002F2.concurrent-url-checker\u002F2.cancellation-and-tests",{"title":333,"path":334,"stem":335,"children":336},"File-backed API","\u002Fprojects\u002Ffile-backed-api","7.projects\u002F3.file-backed-api\u002Findex",[337,339,343],{"title":338,"path":334,"stem":335},"File-backed notes API",{"title":340,"path":341,"stem":342},"File store and concurrency","\u002Fprojects\u002Ffile-backed-api\u002Ffile-store-and-concurrency","7.projects\u002F3.file-backed-api\u002F1.file-store-and-concurrency",{"title":344,"path":345,"stem":346},"HTTP layer and tests","\u002Fprojects\u002Ffile-backed-api\u002Fhttp-and-tests","7.projects\u002F3.file-backed-api\u002F2.http-and-tests",{"title":348,"path":349,"stem":350,"children":351},"Production REST API","\u002Fprojects\u002Fproduction-rest-api","7.projects\u002F4.production-rest-api\u002Findex",[352,354,358],{"title":353,"path":349,"stem":350},"Production REST API capstone",{"title":355,"path":356,"stem":357},"Persistence and authentication","\u002Fprojects\u002Fproduction-rest-api\u002Fpersistence-and-auth","7.projects\u002F4.production-rest-api\u002F1.persistence-and-auth",{"title":359,"path":360,"stem":361},"Operations and release","\u002Fprojects\u002Fproduction-rest-api\u002Foperations-and-release","7.projects\u002F4.production-rest-api\u002F2.operations-and-release",{"title":363,"path":364,"stem":365,"children":366,"page":6},"Meta","\u002Fmeta","99.meta",[367,372],{"title":368,"path":369,"stem":370,"icon":371},"About","\u002Fmeta\u002Fabout","99.meta\u002F1.about","i-lucide-info",{"title":373,"path":374,"stem":375,"icon":376},"Acknowledgements","\u002Fmeta\u002Facknowledgements","99.meta\u002F2.acknowledgements","i-lucide-heart-handshake",{"id":378,"title":275,"body":379,"description":1358,"extension":1359,"links":1360,"meta":1361,"navigation":1362,"path":276,"seo":1363,"stem":277,"__hash__":1365},"docs\u002F6.advanced-go\u002F6.advanced-concurrency.md",{"type":380,"value":381,"toc":1344},"minimark",[382,388,393,397,416,420,423,443,446,450,749,752,756,1012,1019,1022,1026,1041,1048,1052,1055,1069,1076,1083,1087,1090,1093,1104,1108,1111,1128,1131,1135,1142,1145,1149,1187,1191,1194,1303,1307,1324,1334,1337,1340],[383,384],"learning-lesson-meta",{"level":385,"prerequisites":386,"time":387},"Advanced","Goroutines, channels, select, context, synchronization, and error handling","75–90 minutes",[389,390,392],"h2",{"id":391},"what-you-will-learn","What you will learn",[394,395,396],"p",{},"By the end of this lesson, you will be able to:",[398,399,400,404,407,410,413],"ul",{},[401,402,403],"li",{},"design a pipeline with clear channel ownership;",[401,405,406],{},"bound concurrency and queued work;",[401,408,409],{},"propagate cancellation and the first meaningful error;",[401,411,412],{},"distinguish fan-out, fan-in, semaphore, and worker-pool designs;",[401,414,415],{},"reason about goroutine leaks and partial results.",[389,417,419],{"id":418},"begin-with-ownership","Begin with ownership",[394,421,422],{},"For every channel, document:",[398,424,425,428,431,434,437,440],{},[401,426,427],{},"who creates it;",[401,429,430],{},"who sends;",[401,432,433],{},"who receives;",[401,435,436],{},"who closes it;",[401,438,439],{},"what cancellation means;",[401,441,442],{},"whether every sent value must be processed.",[394,444,445],{},"The goroutine that owns all sends is normally responsible for closing the channel. Receivers should not close a channel merely because they are finished receiving.",[389,447,449],{"id":448},"a-pipeline-stage","A pipeline stage",[451,452,457],"pre",{"className":453,"code":454,"language":455,"meta":456,"style":456},"language-go shiki shiki-themes solarized-light material-theme one-dark-pro","func square(ctx context.Context, input \u003C-chan int) \u003C-chan int {\n    output := make(chan int)\n    go func() {\n        defer close(output)\n        for {\n            select {\n            case \u003C-ctx.Done():\n                return\n            case value, ok := \u003C-input:\n                if !ok {\n                    return\n                }\n                select {\n                case output \u003C- value * value:\n                case \u003C-ctx.Done():\n                    return\n                }\n            }\n        }\n    }()\n    return output\n}\n","go","",[458,459,460,520,543,558,574,582,590,608,614,637,651,657,663,671,691,706,711,716,722,728,734,743],"code",{"__ignoreMap":456},[461,462,465,469,473,477,481,485,488,491,494,497,501,504,508,511,513,515,517],"span",{"class":463,"line":464},"line",1,[461,466,468],{"class":467},"sEOdo","func",[461,470,472],{"class":471},"sisdC"," square",[461,474,476],{"class":475},"shFME","(",[461,478,480],{"class":479},"syre3","ctx",[461,482,484],{"class":483},"snwKR"," context",[461,486,487],{"class":475},".",[461,489,490],{"class":483},"Context",[461,492,493],{"class":475},",",[461,495,496],{"class":479}," input",[461,498,500],{"class":499},"sRBoR"," \u003C-",[461,502,503],{"class":467},"chan",[461,505,507],{"class":506},"sF6sA"," int",[461,509,510],{"class":475},")",[461,512,500],{"class":499},[461,514,503],{"class":467},[461,516,507],{"class":506},[461,518,519],{"class":475}," {\n",[461,521,523,527,531,534,536,538,540],{"class":463,"line":522},2,[461,524,526],{"class":525},"s45-6","    output",[461,528,530],{"class":529},"su2KV"," :=",[461,532,533],{"class":471}," make",[461,535,476],{"class":475},[461,537,503],{"class":467},[461,539,507],{"class":506},[461,541,542],{"class":475},")\n",[461,544,546,550,553,556],{"class":463,"line":545},3,[461,547,549],{"class":548},"s7Bcg","    go",[461,551,552],{"class":467}," func",[461,554,555],{"class":475},"()",[461,557,519],{"class":475},[461,559,561,564,567,569,572],{"class":463,"line":560},4,[461,562,563],{"class":548},"        defer",[461,565,566],{"class":471}," close",[461,568,476],{"class":475},[461,570,571],{"class":525},"output",[461,573,542],{"class":475},[461,575,577,580],{"class":463,"line":576},5,[461,578,579],{"class":548},"        for",[461,581,519],{"class":475},[461,583,585,588],{"class":463,"line":584},6,[461,586,587],{"class":548},"            select",[461,589,519],{"class":475},[461,591,593,596,598,600,602,605],{"class":463,"line":592},7,[461,594,595],{"class":548},"            case",[461,597,500],{"class":499},[461,599,480],{"class":525},[461,601,487],{"class":475},[461,603,604],{"class":471},"Done",[461,606,607],{"class":475},"():\n",[461,609,611],{"class":463,"line":610},8,[461,612,613],{"class":548},"                return\n",[461,615,617,619,622,624,627,629,631,634],{"class":463,"line":616},9,[461,618,595],{"class":548},[461,620,621],{"class":525}," value",[461,623,493],{"class":475},[461,625,626],{"class":525}," ok",[461,628,530],{"class":529},[461,630,500],{"class":499},[461,632,633],{"class":525},"input",[461,635,636],{"class":475},":\n",[461,638,640,643,646,649],{"class":463,"line":639},10,[461,641,642],{"class":548},"                if",[461,644,645],{"class":499}," !",[461,647,648],{"class":525},"ok",[461,650,519],{"class":475},[461,652,654],{"class":463,"line":653},11,[461,655,656],{"class":548},"                    return\n",[461,658,660],{"class":463,"line":659},12,[461,661,662],{"class":475},"                }\n",[461,664,666,669],{"class":463,"line":665},13,[461,667,668],{"class":548},"                select",[461,670,519],{"class":475},[461,672,674,677,680,682,684,687,689],{"class":463,"line":673},14,[461,675,676],{"class":548},"                case",[461,678,679],{"class":525}," output",[461,681,500],{"class":499},[461,683,621],{"class":525},[461,685,686],{"class":467}," *",[461,688,621],{"class":525},[461,690,636],{"class":475},[461,692,694,696,698,700,702,704],{"class":463,"line":693},15,[461,695,676],{"class":548},[461,697,500],{"class":499},[461,699,480],{"class":525},[461,701,487],{"class":475},[461,703,604],{"class":471},[461,705,607],{"class":475},[461,707,709],{"class":463,"line":708},16,[461,710,656],{"class":548},[461,712,714],{"class":463,"line":713},17,[461,715,662],{"class":475},[461,717,719],{"class":463,"line":718},18,[461,720,721],{"class":475},"            }\n",[461,723,725],{"class":463,"line":724},19,[461,726,727],{"class":475},"        }\n",[461,729,731],{"class":463,"line":730},20,[461,732,733],{"class":475},"    }()\n",[461,735,737,740],{"class":463,"line":736},21,[461,738,739],{"class":548},"    return",[461,741,742],{"class":525}," output\n",[461,744,746],{"class":463,"line":745},22,[461,747,748],{"class":475},"}\n",[394,750,751],{},"Cancellation is checked while receiving and sending. Without the second check, the goroutine can leak when downstream stops reading.",[389,753,755],{"id":754},"bound-work-with-a-fixed-worker-pool","Bound work with a fixed worker pool",[451,757,759],{"className":453,"code":758,"language":455,"meta":456,"style":456},"func worker(ctx context.Context, jobs \u003C-chan Job, results chan\u003C- Result) error {\n    for {\n        select {\n        case \u003C-ctx.Done():\n            return ctx.Err()\n        case job, ok := \u003C-jobs:\n            if !ok {\n                return nil\n            }\n            result, err := process(ctx, job)\n            if err != nil {\n                return err\n            }\n            select {\n            case results \u003C- result:\n            case \u003C-ctx.Done():\n                return ctx.Err()\n            }\n        }\n    }\n}\n",[458,760,761,811,818,825,840,856,876,887,896,900,925,939,946,950,956,969,983,995,999,1003,1008],{"__ignoreMap":456},[461,762,763,765,768,770,772,774,776,778,780,783,785,787,790,792,795,798,801,804,806,809],{"class":463,"line":464},[461,764,468],{"class":467},[461,766,767],{"class":471}," worker",[461,769,476],{"class":475},[461,771,480],{"class":479},[461,773,484],{"class":483},[461,775,487],{"class":475},[461,777,490],{"class":483},[461,779,493],{"class":475},[461,781,782],{"class":479}," jobs",[461,784,500],{"class":499},[461,786,503],{"class":467},[461,788,789],{"class":483}," Job",[461,791,493],{"class":475},[461,793,794],{"class":479}," results",[461,796,797],{"class":467}," chan",[461,799,800],{"class":499},"\u003C-",[461,802,803],{"class":483}," Result",[461,805,510],{"class":475},[461,807,808],{"class":506}," error",[461,810,519],{"class":475},[461,812,813,816],{"class":463,"line":522},[461,814,815],{"class":548},"    for",[461,817,519],{"class":475},[461,819,820,823],{"class":463,"line":545},[461,821,822],{"class":548},"        select",[461,824,519],{"class":475},[461,826,827,830,832,834,836,838],{"class":463,"line":560},[461,828,829],{"class":548},"        case",[461,831,500],{"class":499},[461,833,480],{"class":525},[461,835,487],{"class":475},[461,837,604],{"class":471},[461,839,607],{"class":475},[461,841,842,845,848,850,853],{"class":463,"line":576},[461,843,844],{"class":548},"            return",[461,846,847],{"class":525}," ctx",[461,849,487],{"class":475},[461,851,852],{"class":471},"Err",[461,854,855],{"class":475},"()\n",[461,857,858,860,863,865,867,869,871,874],{"class":463,"line":584},[461,859,829],{"class":548},[461,861,862],{"class":525}," job",[461,864,493],{"class":475},[461,866,626],{"class":525},[461,868,530],{"class":529},[461,870,500],{"class":499},[461,872,873],{"class":525},"jobs",[461,875,636],{"class":475},[461,877,878,881,883,885],{"class":463,"line":592},[461,879,880],{"class":548},"            if",[461,882,645],{"class":499},[461,884,648],{"class":525},[461,886,519],{"class":475},[461,888,889,892],{"class":463,"line":610},[461,890,891],{"class":548},"                return",[461,893,895],{"class":894},"sp8Z5"," nil\n",[461,897,898],{"class":463,"line":616},[461,899,721],{"class":475},[461,901,902,905,907,910,912,915,917,919,921,923],{"class":463,"line":639},[461,903,904],{"class":525},"            result",[461,906,493],{"class":475},[461,908,909],{"class":525}," err",[461,911,530],{"class":529},[461,913,914],{"class":471}," process",[461,916,476],{"class":475},[461,918,480],{"class":525},[461,920,493],{"class":475},[461,922,862],{"class":525},[461,924,542],{"class":475},[461,926,927,929,931,934,937],{"class":463,"line":653},[461,928,880],{"class":548},[461,930,909],{"class":525},[461,932,933],{"class":499}," !=",[461,935,936],{"class":894}," nil",[461,938,519],{"class":475},[461,940,941,943],{"class":463,"line":659},[461,942,891],{"class":548},[461,944,945],{"class":525}," err\n",[461,947,948],{"class":463,"line":665},[461,949,721],{"class":475},[461,951,952,954],{"class":463,"line":673},[461,953,587],{"class":548},[461,955,519],{"class":475},[461,957,958,960,962,964,967],{"class":463,"line":693},[461,959,595],{"class":548},[461,961,794],{"class":525},[461,963,500],{"class":499},[461,965,966],{"class":525}," result",[461,968,636],{"class":475},[461,970,971,973,975,977,979,981],{"class":463,"line":708},[461,972,595],{"class":548},[461,974,500],{"class":499},[461,976,480],{"class":525},[461,978,487],{"class":475},[461,980,604],{"class":471},[461,982,607],{"class":475},[461,984,985,987,989,991,993],{"class":463,"line":713},[461,986,891],{"class":548},[461,988,847],{"class":525},[461,990,487],{"class":475},[461,992,852],{"class":471},[461,994,855],{"class":475},[461,996,997],{"class":463,"line":718},[461,998,721],{"class":475},[461,1000,1001],{"class":463,"line":724},[461,1002,727],{"class":475},[461,1004,1005],{"class":463,"line":730},[461,1006,1007],{"class":475},"    }\n",[461,1009,1010],{"class":463,"line":736},[461,1011,748],{"class":475},[394,1013,1014,1015,1018],{},"Start a fixed number of workers. The worker count bounds simultaneous ",[458,1016,1017],{},"process"," calls. A bounded jobs channel limits queued work and creates backpressure.",[394,1020,1021],{},"Worker count should reflect the constrained resource. More workers can increase contention, database pool waits, rate-limit failures, or memory use.",[389,1023,1025],{"id":1024},"fan-out-and-fan-in","Fan-out and fan-in",[398,1027,1028,1035],{},[401,1029,1030,1034],{},[1031,1032,1033],"strong",{},"Fan-out:"," several workers receive from one input channel.",[401,1036,1037,1040],{},[1031,1038,1039],{},"Fan-in:"," one coordinator combines several output channels into one.",[394,1042,1043,1044,1047],{},"When fanning in, the coordinator closes the combined output only after every forwarding goroutine finishes. A ",[458,1045,1046],{},"WaitGroup"," can coordinate those forwarders.",[389,1049,1051],{"id":1050},"error-propagation","Error propagation",[394,1053,1054],{},"Decide whether:",[398,1056,1057,1060,1063,1066],{},[401,1058,1059],{},"the first error cancels all work;",[401,1061,1062],{},"errors are collected while independent work continues;",[401,1064,1065],{},"partial results are valid;",[401,1067,1068],{},"failed jobs are retried or returned to a durable queue.",[394,1070,1071,1072,1075],{},"Do not add an error channel without defining who drains it and who closes it. A single buffered result containing ",[458,1073,1074],{},"{Value, Err}"," is sometimes clearer.",[394,1077,1078,1079,1082],{},"The external ",[458,1080,1081],{},"golang.org\u002Fx\u002Fsync\u002Ferrgroup"," package provides a useful pattern for related goroutines with error propagation and context cancellation. Understand its documented limits—such as whether goroutine count is bounded for your use—before adopting it.",[389,1084,1086],{"id":1085},"semaphores","Semaphores",[394,1088,1089],{},"A semaphore bounds entry to an operation while allowing goroutines to be started elsewhere. A worker pool bounds both worker goroutines and, with a bounded input, queued work.",[394,1091,1092],{},"Choose based on ownership:",[398,1094,1095,1098,1101],{},[401,1096,1097],{},"fixed stream of jobs with backpressure → worker pool;",[401,1099,1100],{},"occasional independent operations sharing a scarce limit → semaphore may fit;",[401,1102,1103],{},"simple shared data invariant → mutex may be clearer than channels.",[389,1105,1107],{"id":1106},"backpressure","Backpressure",[394,1109,1110],{},"When producers are faster than consumers, the system must:",[398,1112,1113,1116,1119,1122,1125],{},[401,1114,1115],{},"block producers;",[401,1117,1118],{},"buffer up to a fixed bound;",[401,1120,1121],{},"reject or shed work;",[401,1123,1124],{},"persist work durably;",[401,1126,1127],{},"scale consumers within safe limits.",[394,1129,1130],{},"An unbounded in-memory queue only delays failure while memory grows.",[389,1132,1134],{"id":1133},"cancellation-is-not-cleanup-completion","Cancellation is not cleanup completion",[394,1136,1137,1138,1141],{},"Calling ",[458,1139,1140],{},"cancel()"," requests that work stop. The caller must still wait for owned goroutines to return before closing dependencies they use.",[394,1143,1144],{},"Design blocking library calls with contexts or other interruption mechanisms. A goroutine cannot be safely killed from outside.",[389,1146,1148],{"id":1147},"common-mistakes","Common mistakes",[398,1150,1151,1157,1163,1169,1175,1181],{},[401,1152,1153,1156],{},[1031,1154,1155],{},"Starting one goroutine per item without a bound:"," a traffic spike becomes a resource spike.",[401,1158,1159,1162],{},[1031,1160,1161],{},"Returning early while upstream still sends:"," upstream goroutines block forever.",[401,1164,1165,1168],{},[1031,1166,1167],{},"Closing a shared input from one receiver:"," other senders panic.",[401,1170,1171,1174],{},[1031,1172,1173],{},"Using a large buffer to hide deadlock:"," ownership remains incorrect.",[401,1176,1177,1180],{},[1031,1178,1179],{},"Assuming scheduler fairness:"," correctness must not depend on a goroutine receiving an equal turn within a precise time.",[401,1182,1183,1186],{},[1031,1184,1185],{},"Cancelling but not waiting:"," dependencies close while goroutines still use them.",[389,1188,1190],{"id":1189},"practice","Practice",[394,1192,1193],{},"Build a bounded URL-check pipeline with five workers, at most twenty queued jobs, per-request timeout, first-error cancellation option, ordered result reconstruction, and complete goroutine cleanup.",[1195,1196,1197],"accordion",{},[1198,1199,1202,1288,1296],"accordion-item",{"icon":1200,"label":1201},"i-lucide-lightbulb","Show architecture and key types",[451,1203,1205],{"className":453,"code":1204,"language":455,"meta":456,"style":456},"type Job struct {\n    Index int\n    URL   string\n}\n\ntype Result struct {\n    Index  int\n    URL    string\n    Status int\n    Err    error\n}\n",[458,1206,1207,1219,1227,1235,1239,1245,1255,1262,1269,1276,1284],{"__ignoreMap":456},[461,1208,1209,1212,1214,1217],{"class":463,"line":464},[461,1210,1211],{"class":467},"type",[461,1213,789],{"class":483},[461,1215,1216],{"class":467}," struct",[461,1218,519],{"class":475},[461,1220,1221,1224],{"class":463,"line":522},[461,1222,1223],{"class":525},"    Index",[461,1225,1226],{"class":506}," int\n",[461,1228,1229,1232],{"class":463,"line":545},[461,1230,1231],{"class":525},"    URL",[461,1233,1234],{"class":506},"   string\n",[461,1236,1237],{"class":463,"line":560},[461,1238,748],{"class":475},[461,1240,1241],{"class":463,"line":576},[461,1242,1244],{"emptyLinePlaceholder":1243},true,"\n",[461,1246,1247,1249,1251,1253],{"class":463,"line":584},[461,1248,1211],{"class":467},[461,1250,803],{"class":483},[461,1252,1216],{"class":467},[461,1254,519],{"class":475},[461,1256,1257,1259],{"class":463,"line":592},[461,1258,1223],{"class":525},[461,1260,1261],{"class":506},"  int\n",[461,1263,1264,1266],{"class":463,"line":610},[461,1265,1231],{"class":525},[461,1267,1268],{"class":506},"    string\n",[461,1270,1271,1274],{"class":463,"line":616},[461,1272,1273],{"class":525},"    Status",[461,1275,1226],{"class":506},[461,1277,1278,1281],{"class":463,"line":639},[461,1279,1280],{"class":525},"    Err",[461,1282,1283],{"class":506},"    error\n",[461,1285,1286],{"class":463,"line":653},[461,1287,748],{"class":475},[451,1289,1294],{"className":1290,"code":1292,"language":1293,"meta":456},[1291],"language-text","caller owns context\n  ↓\nproducer sends indexed jobs into buffer(capacity 20), then closes jobs\n  ↓\nfive workers receive jobs and send one Result per accepted job\n  ↓\ncoordinator waits for workers, then closes results\n  ↓\ncollector stores results by Index and returns in input order\n","text",[458,1295,1292],{"__ignoreMap":456},[394,1297,1298,1299,1302],{},"Each HTTP request uses ",[458,1300,1301],{},"NewRequestWithContext"," with the worker context and a shared configured client. Every successful response body is closed. If first-error mode is enabled, the collector cancels context but continues draining until the coordinator closes results, preventing blocked sends. The caller waits for all worker completion before returning.",[389,1304,1306],{"id":1305},"summary","Summary",[398,1308,1309,1312,1315,1318,1321],{},[401,1310,1311],{},"Document channel creation, sending, receiving, closing, cancellation, and delivery semantics.",[401,1313,1314],{},"Bound simultaneous work and queued work separately.",[401,1316,1317],{},"Check cancellation around both receives and sends in pipelines.",[401,1319,1320],{},"Decide how errors and partial results affect sibling work.",[401,1322,1323],{},"Cancellation requests shutdown; waiting confirms completion.",[394,1325,1326,1327,487],{},"Official reference: ",[1328,1329,1333],"a",{"href":1330,"rel":1331},"https:\u002F\u002Fgo.dev\u002Fblog\u002Fpipelines",[1332],"nofollow","Go Concurrency Patterns: Pipelines and cancellation",[1335,1336],"learning-lesson-complete",{},[1338,1339],"learning-lesson-navigation",{"next":280,"next-label":279,"previous":271,"previous-label":270},[1341,1342,1343],"style",{},"html pre.shiki code .sEOdo, html code.shiki .sEOdo{--shiki-light:#859900;--shiki-default:#89DDFF;--shiki-dark:#C678DD}html pre.shiki code .sisdC, html code.shiki .sisdC{--shiki-light:#268BD2;--shiki-default:#82AAFF;--shiki-dark:#61AFEF}html pre.shiki code .shFME, html code.shiki .shFME{--shiki-light:#657B83;--shiki-default:#89DDFF;--shiki-dark:#ABB2BF}html pre.shiki code .syre3, html code.shiki .syre3{--shiki-light:#657B83;--shiki-light-font-style:inherit;--shiki-default:#EEFFFF;--shiki-default-font-style:italic;--shiki-dark:#E06C75;--shiki-dark-font-style:italic}html pre.shiki code .snwKR, html code.shiki .snwKR{--shiki-light:#CB4B16;--shiki-default:#FFCB6B;--shiki-dark:#E5C07B}html pre.shiki code .sRBoR, html code.shiki .sRBoR{--shiki-light:#859900;--shiki-default:#89DDFF;--shiki-dark:#56B6C2}html pre.shiki code .sF6sA, html code.shiki .sF6sA{--shiki-light:#586E75;--shiki-light-font-weight:bold;--shiki-default:#C792EA;--shiki-default-font-weight:inherit;--shiki-dark:#C678DD;--shiki-dark-font-weight:inherit}html pre.shiki code .s45-6, html code.shiki .s45-6{--shiki-light:#268BD2;--shiki-default:#EEFFFF;--shiki-dark:#E06C75}html pre.shiki code .su2KV, html code.shiki .su2KV{--shiki-light:#859900;--shiki-default:#89DDFF;--shiki-dark:#E5C07B}html pre.shiki code .s7Bcg, html code.shiki .s7Bcg{--shiki-light:#859900;--shiki-light-font-style:inherit;--shiki-default:#89DDFF;--shiki-default-font-style:italic;--shiki-dark:#C678DD;--shiki-dark-font-style:inherit}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sp8Z5, html code.shiki .sp8Z5{--shiki-light:#B58900;--shiki-default:#89DDFF;--shiki-dark:#D19A66}",{"title":456,"searchDepth":522,"depth":522,"links":1345},[1346,1347,1348,1349,1350,1351,1352,1353,1354,1355,1356,1357],{"id":391,"depth":522,"text":392},{"id":418,"depth":522,"text":419},{"id":448,"depth":522,"text":449},{"id":754,"depth":522,"text":755},{"id":1024,"depth":522,"text":1025},{"id":1050,"depth":522,"text":1051},{"id":1085,"depth":522,"text":1086},{"id":1106,"depth":522,"text":1107},{"id":1133,"depth":522,"text":1134},{"id":1147,"depth":522,"text":1148},{"id":1189,"depth":522,"text":1190},{"id":1305,"depth":522,"text":1306},"Design bounded pipelines with cancellation, backpressure, error propagation, and explicit ownership.","md",null,{},{"icon":48},{"description":1364,"title":275},"Learn advanced Go concurrency patterns including bounded worker pools, pipelines, fan-out, fan-in, backpressure, cancellation, and error ownership.","n5OSA5T3xyIuZR8SQ3FNScM7d8XPIJVFsKSgZ7m5tZw",[1367,1369],{"title":270,"path":271,"stem":272,"description":1368,"icon":273,"children":-1},"Control dependencies, test properties and boundaries, fuzz parsers, and keep suites deterministic.",{"title":279,"path":280,"stem":281,"description":1370,"icon":282,"children":-1},"Understand what guarantees are lost when using unsafe or cgo and how to isolate the risk.",1794118103522]