Skip to content

Commit

Permalink
working goroutines
Browse files Browse the repository at this point in the history
  • Loading branch information
sermuns committed Jan 28, 2025
1 parent 6a3102c commit 8744941
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 76 deletions.
30 changes: 0 additions & 30 deletions typst-testing/he.svg

This file was deleted.

38 changes: 23 additions & 15 deletions typst-testing/main.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package main

import (
"bytes"
"fmt"
"log"
"os"
"os/exec"
"strings"
"sync"
"time"
)

func main() {
inp := bytes.NewBufferString("#set page(width: auto, height: auto, margin: 0cm, fill: none)\n")
start := time.Now()
var inp strings.Builder
inp.WriteString("#set page(width: auto, height: auto, fill: none)\n")

args := os.Args
if len(args) < 2 {
Expand All @@ -18,18 +22,22 @@ func main() {

inp.WriteString(args[1])

cmd := exec.Command("typst", "compile", "--format", "svg", "-", "out.svg")
cmd.Stdin = inp
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
time.Sleep(time.Second)
inp.WriteString(args[1])
time.Sleep(time.Second)
inp.WriteString(args[1])
time.Sleep(time.Second)
inp.WriteString(args[1])
if err != nil {
log.Fatal(err)
var wg sync.WaitGroup
for i := 0; i < 50; i++ {
wg.Add(1)
go func() {
defer wg.Done()
cmd := exec.Command("typst", "compile", "--format", "svg", "-", "-")
cmd.Stdin = strings.NewReader(inp.String())
// cmd.Stdout = os.Stdout
// cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
log.Fatal(err)
}
}()
}
wg.Wait()

fmt.Println("Took", time.Since(start))
}
30 changes: 0 additions & 30 deletions typst-testing/out.svg

This file was deleted.

1 change: 0 additions & 1 deletion typst-testing/test.typ

This file was deleted.

0 comments on commit 8744941

Please sign in to comment.