Files

62 lines
1.2 KiB
TypeScript

import { CodeEditor } from "@/registry/default/ui/code-editor"
export default function CodeEditorHeightDemo() {
return (
<CodeEditor
defaultValue={`package main
import (
"fmt"
"sync"
"time"
)
// Worker simulates a concurrent task
func worker(id int, jobs <-chan int, results chan<- int, wg *sync.WaitGroup) {
defer wg.Done()
for job := range jobs {
fmt.Printf("Worker %d processing job %d\\n", id, job)
time.Sleep(time.Second) // Simulate work
results <- job * 2
}
}
func main() {
const numWorkers = 3
const numJobs = 10
jobs := make(chan int, numJobs)
results := make(chan int, numJobs)
var wg sync.WaitGroup
// Start workers
for w := 1; w <= numWorkers; w++ {
wg.Add(1)
go worker(w, jobs, results, &wg)
}
// Send jobs
for j := 1; j <= numJobs; j++ {
jobs <- j
}
close(jobs)
// Wait for all workers to finish
go func() {
wg.Wait()
close(results)
}()
// Collect results
for result := range results {
fmt.Printf("Result: %d\\n", result)
}
}`}
language="go"
height="600px"
/>
)
}