mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-06 01:05:48 +02:00
Make various goroutines panic-safe
This commit is contained in:
@@ -32,7 +32,7 @@ var highlighter = sync.OnceValue(func() highlight.Highlighter {
|
||||
func highlight_all(paths []string, light bool) {
|
||||
ctx := images.Context{}
|
||||
srd := prefer_light_colors(light)
|
||||
ctx.Parallel(0, len(paths), func(nums <-chan int) {
|
||||
if err := ctx.SafeParallel(0, len(paths), func(nums <-chan int) {
|
||||
for i := range nums {
|
||||
path := paths[i]
|
||||
raw, err := highlighter().HighlightFile(path, &srd)
|
||||
@@ -45,5 +45,7 @@ func highlight_all(paths []string, light bool) {
|
||||
dark_highlighted_lines_cache.Set(path, text_to_lines(raw))
|
||||
}
|
||||
}
|
||||
})
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,14 +358,16 @@ func diff(jobs []diff_job, context_count int) (ans map[string]*Patch, err error)
|
||||
patch *Patch
|
||||
}
|
||||
results := make(chan result, len(jobs))
|
||||
ctx.Parallel(0, len(jobs), func(nums <-chan int) {
|
||||
if err := ctx.SafeParallel(0, len(jobs), func(nums <-chan int) {
|
||||
for i := range nums {
|
||||
job := jobs[i]
|
||||
r := result{file1: job.file1, file2: job.file2}
|
||||
r.patch, r.err = do_diff(job.file1, job.file2, context_count)
|
||||
results <- r
|
||||
}
|
||||
})
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
close(results)
|
||||
for r := range results {
|
||||
if r.err != nil {
|
||||
|
||||
@@ -106,7 +106,7 @@ func (self *Search) search(logical_lines *LogicalLines) {
|
||||
self.matches = make(map[ScrollPos][]Span)
|
||||
ctx := images.Context{}
|
||||
mutex := sync.Mutex{}
|
||||
ctx.Parallel(0, logical_lines.Len(), func(nums <-chan int) {
|
||||
if err := ctx.SafeParallel(0, logical_lines.Len(), func(nums <-chan int) {
|
||||
for i := range nums {
|
||||
line := logical_lines.At(i)
|
||||
if line.line_type == EMPTY_LINE || line.line_type == IMAGE_LINE {
|
||||
@@ -121,7 +121,9 @@ func (self *Search) search(logical_lines *LogicalLines) {
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, spans := range self.matches {
|
||||
slices.SortFunc(spans, func(a, b Span) int { return a.start - b.start })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user