Skip to content

Commit

Permalink
Updated to use net.http instead of vweb
Browse files Browse the repository at this point in the history
  • Loading branch information
ulises-jeremias committed Oct 17, 2023
1 parent 84d3330 commit 97f893b
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions plot/show.v
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ import net.http
import os
import time

// port is the port to run the server on. If 0, it will run on the next available port.
const port = 8080

type TracesWithTypeValue = Trace | string

struct PlotlyHandler {
Expand All @@ -35,10 +32,11 @@ pub fn (plot Plot) show() ! {
$if test ? {
println('Ignoring plot.show() because we are running in test mode')
} $else {
port := 8080
ch := chan int{}
mut server := &http.Server{
accept_timeout: 1 * time.second
port: plot.port
port: port
handler: PlotlyHandler{
plot: plot
ch: ch
Expand All @@ -48,7 +46,7 @@ pub fn (plot Plot) show() ! {
for server.status() != .running {
time.sleep(10 * time.millisecond)
}
os.open_uri('http://localhost:${plot.port}')!
os.open_uri('http://localhost:${port}')!
_ := <-ch
server.close()
t.wait()
Expand Down

0 comments on commit 97f893b

Please sign in to comment.