11import { HostProcessPlatform } from "@t3tools/shared/hostProcess" ;
22import * as Data from "effect/Data" ;
3+ import * as Duration from "effect/Duration" ;
34import * as Effect from "effect/Effect" ;
45import * as Option from "effect/Option" ;
56import * as Schema from "effect/Schema" ;
@@ -8,9 +9,9 @@ import { HttpClient, HttpClientRequest } from "effect/unstable/http";
89import { ChildProcess , ChildProcessSpawner } from "effect/unstable/process" ;
910
1011export const DEFAULT_TAILSCALE_SERVE_PORT = 443 ;
11- export const TAILSCALE_STATUS_TIMEOUT_MS = 1_500 ;
12- export const TAILSCALE_SERVE_TIMEOUT_MS = 10_000 ;
13- export const TAILSCALE_PROBE_TIMEOUT_MS = 2_500 ;
12+ export const TAILSCALE_STATUS_TIMEOUT = Duration . millis ( 1_500 ) ;
13+ export const TAILSCALE_SERVE_TIMEOUT = Duration . seconds ( 10 ) ;
14+ export const TAILSCALE_PROBE_TIMEOUT = Duration . millis ( 2_500 ) ;
1415
1516// tailscale is a real executable everywhere (`tailscale.exe` on Windows), so
1617// it is always spawned directly rather than through cmd.exe shell mode.
@@ -180,7 +181,7 @@ export const readTailscaleStatus: Effect.Effect<
180181 return yield * parseTailscaleStatus ( stdout ) ;
181182} ) . pipe (
182183 Effect . scoped ,
183- Effect . timeoutOption ( TAILSCALE_STATUS_TIMEOUT_MS ) ,
184+ Effect . timeoutOption ( TAILSCALE_STATUS_TIMEOUT ) ,
184185 Effect . flatMap ( ( result ) =>
185186 Option . match ( result , {
186187 onNone : ( ) =>
@@ -212,7 +213,7 @@ const runTailscaleCommand = (
212213 readonly runMessage : string ;
213214 readonly exitMessage : ( exitCode : number ) => string ;
214215 readonly timeoutMessage : string ;
215- readonly timeoutMs : number ;
216+ readonly timeout : Duration . Input ;
216217 } ,
217218) : Effect . Effect < void , TailscaleCommandError , ChildProcessSpawner . ChildProcessSpawner > =>
218219 Effect . gen ( function * ( ) {
@@ -246,7 +247,7 @@ const runTailscaleCommand = (
246247 }
247248 } ) . pipe (
248249 Effect . scoped ,
249- Effect . timeoutOption ( input . timeoutMs ) ,
250+ Effect . timeoutOption ( input . timeout ) ,
250251 Effect . flatMap ( ( result ) =>
251252 Option . match ( result , {
252253 onNone : ( ) => Effect . fail ( tailscaleCommandError ( args , input . timeoutMessage , null ) ) ,
@@ -268,7 +269,7 @@ export const ensureTailscaleServe = (input: {
268269 runMessage : "Failed to run tailscale serve." ,
269270 exitMessage : ( exitCode ) => `Tailscale serve exited with code ${ exitCode } .` ,
270271 timeoutMessage : "Tailscale serve timed out." ,
271- timeoutMs : TAILSCALE_SERVE_TIMEOUT_MS ,
272+ timeout : TAILSCALE_SERVE_TIMEOUT ,
272273 } ) ;
273274} ;
274275
@@ -284,21 +285,21 @@ export const disableTailscaleServe = (
284285 runMessage : "Failed to run tailscale serve off." ,
285286 exitMessage : ( exitCode ) => `Tailscale serve off exited with code ${ exitCode } .` ,
286287 timeoutMessage : "Tailscale serve off timed out." ,
287- timeoutMs : TAILSCALE_SERVE_TIMEOUT_MS ,
288+ timeout : TAILSCALE_SERVE_TIMEOUT ,
288289 } ) ;
289290 } ) ;
290291
291292export const probeTailscaleHttpsEndpoint = ( input : {
292293 readonly baseUrl : string ;
293- readonly timeoutMs ?: number ;
294+ readonly timeout ?: Duration . Input ;
294295} ) : Effect . Effect < boolean , never , HttpClient . HttpClient > =>
295296 Effect . gen ( function * ( ) {
296297 const client = yield * HttpClient . HttpClient ;
297298 const response = yield * Effect . gen ( function * ( ) {
298299 const url = new URL ( "/.well-known/t3/environment" , input . baseUrl ) ;
299300 const request = HttpClientRequest . get ( url . toString ( ) ) ;
300301 return yield * client . execute ( request ) ;
301- } ) . pipe ( Effect . timeoutOption ( input . timeoutMs ?? TAILSCALE_PROBE_TIMEOUT_MS ) ) ;
302+ } ) . pipe ( Effect . timeoutOption ( input . timeout ?? TAILSCALE_PROBE_TIMEOUT ) ) ;
302303
303304 return Option . match ( response , {
304305 onNone : ( ) => false ,
0 commit comments