File tree Expand file tree Collapse file tree 2 files changed +11
-12
lines changed Expand file tree Collapse file tree 2 files changed +11
-12
lines changed Original file line number Diff line number Diff line change 2
2
3
3
package runtime
4
4
5
- type timeUnit float64 // time in milliseconds, just like Date.now() in JavaScript
5
+ type timeUnit int64
6
6
7
7
var handleEvent func ()
8
8
@@ -11,17 +11,16 @@ func setEventHandler(fn func()) {
11
11
handleEvent = fn
12
12
}
13
13
14
+ // We use 1ns per tick, to simplify things.
15
+ // It would probably be fine to use 1µs per tick, since performance.now only
16
+ // promises a resolution of 5µs, but 1ns makes the conversions here a bit more
17
+ // straightforward (since nothing needs to be converted).
14
18
func ticksToNanoseconds (ticks timeUnit ) int64 {
15
- // The JavaScript API works in float64 milliseconds, so convert to
16
- // nanoseconds first before converting to a timeUnit (which is a float64),
17
- // to avoid precision loss.
18
- return int64 (ticks * 1e6 )
19
+ return int64 (ticks )
19
20
}
20
21
21
22
func nanosecondsToTicks (ns int64 ) timeUnit {
22
- // The JavaScript API works in float64 milliseconds, so convert to timeUnit
23
- // (which is a float64) first before dividing, to avoid precision loss.
24
- return timeUnit (ns ) / 1e6
23
+ return timeUnit (ns )
25
24
}
26
25
27
26
// This function is called by the scheduler.
Original file line number Diff line number Diff line change 283
283
} ,
284
284
} ,
285
285
gojs : {
286
- // func ticks() float64
286
+ // func ticks() int64
287
287
"runtime.ticks" : ( ) => {
288
- return timeOrigin + performance . now ( ) ;
288
+ return BigInt ( ( timeOrigin + performance . now ( ) ) * 1e6 ) ;
289
289
} ,
290
290
291
- // func sleepTicks(timeout float64 )
291
+ // func sleepTicks(timeout int64 )
292
292
"runtime.sleepTicks" : ( timeout ) => {
293
293
// Do not sleep, only reactivate scheduler after the given timeout.
294
294
setTimeout ( ( ) => {
298
298
} catch ( e ) {
299
299
if ( e !== wasmExit ) throw e ;
300
300
}
301
- } , timeout ) ;
301
+ } , Number ( timeout ) / 1e6 ) ;
302
302
} ,
303
303
304
304
// func finalizeRef(v ref)
You can’t perform that action at this time.
0 commit comments