Skip to content

Commit ea606bf

Browse files
committed
refactor: simplify spinner handling in build.vsh
1 parent 6540b17 commit ea606bf

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

build.vsh

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,14 @@ fn build_docs() ! {
4141

4242
// == Download & Build Library ================================================
4343

44-
fn spinner(ch chan bool) {
44+
fn spinner(ch chan bool, silent bool) {
45+
if silent {
46+
return
47+
}
4548
runes := [`-`, `\\`, `|`, `/`]
4649
mut pos := 0
4750
for {
48-
mut finished := false
49-
ch.try_pop(mut finished)
50-
if finished {
51+
if ch.closed {
5152
print('\r')
5253
return
5354
}
@@ -75,14 +76,12 @@ fn download_webview2() {
7576

7677
fn download(silent bool) {
7778
println('Downloading...')
78-
dl_spinner := chan bool{cap: 1}
79-
if !silent {
80-
spawn spinner(dl_spinner)
81-
}
79+
spinner_ch := chan bool{}
80+
spawn spinner(spinner_ch, silent)
81+
defer { spinner_ch.close() }
8282
http.download_file('${lib_url}/webview.h', '${lib_dir}/webview.h') or { panic(err) }
8383
http.download_file('${lib_url}/webview.cc', '${lib_dir}/webview.cc') or { panic(err) }
8484
download_webview2()
85-
dl_spinner <- true
8685
}
8786

8887
fn build(silent bool) {
@@ -99,12 +98,10 @@ fn build(silent bool) {
9998
cmd += ' -I${lib_dir}/webview2/build/native/include'
10099
}
101100
println('Building...')
102-
build_spinner := chan bool{cap: 1}
103-
if !silent {
104-
spawn spinner(build_spinner)
105-
}
101+
spinner_ch := chan bool{}
102+
spawn spinner(spinner_ch, silent)
103+
defer { spinner_ch.close() }
106104
build_res := execute(cmd)
107-
build_spinner <- true
108105
if build_res.exit_code != 0 {
109106
eprintln(build_res.output)
110107
exit(1)

0 commit comments

Comments
 (0)