mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
fix all duration to delay with mdn description
This commit is contained in:
parent
38a2c042b6
commit
84b0687990
2 changed files with 14 additions and 14 deletions
10
timers.go
10
timers.go
|
@ -12,7 +12,7 @@ type Timer struct {
|
|||
Done bool
|
||||
Cleared bool
|
||||
Interval bool
|
||||
Duration int32 // In milliseconds
|
||||
Delay int32 // In milliseconds
|
||||
}
|
||||
|
||||
var timers = make(map[int32]*Timer)
|
||||
|
@ -28,11 +28,11 @@ func InitTimers() {
|
|||
Id: id,
|
||||
Done: false,
|
||||
Interval: msg.TimerStartInterval,
|
||||
Duration: msg.TimerStartDuration,
|
||||
Delay: msg.TimerStartDelay,
|
||||
Cleared: false,
|
||||
}
|
||||
if t.Duration < 10 {
|
||||
t.Duration = 10
|
||||
if t.Delay < 10 {
|
||||
t.Delay = 10
|
||||
}
|
||||
t.StartTimer()
|
||||
timers[id] = t
|
||||
|
@ -62,7 +62,7 @@ func (t *Timer) StartTimer() {
|
|||
go func() {
|
||||
defer t.Clear()
|
||||
for {
|
||||
time.Sleep(time.Duration(t.Duration) * time.Millisecond)
|
||||
time.Sleep(time.Duration(t.Delay) * time.Millisecond)
|
||||
if !t.Interval {
|
||||
t.Done = true
|
||||
}
|
||||
|
|
18
timers.ts
18
timers.ts
|
@ -15,7 +15,7 @@ interface Timer {
|
|||
interval: boolean;
|
||||
// tslint:disable-next-line:no-any
|
||||
args: any[];
|
||||
duration: number; // milliseconds
|
||||
delay: number; // milliseconds
|
||||
}
|
||||
|
||||
const timers = new Map<number, Timer>();
|
||||
|
@ -41,7 +41,7 @@ function onMessage(payload: Uint8Array) {
|
|||
|
||||
function setTimer(
|
||||
cb: TimerCallback,
|
||||
duration: number,
|
||||
delay: number,
|
||||
interval: boolean,
|
||||
// tslint:disable-next-line:no-any
|
||||
args: any[]
|
||||
|
@ -49,7 +49,7 @@ function setTimer(
|
|||
const timer = {
|
||||
id: nextTimerId++,
|
||||
interval,
|
||||
duration,
|
||||
delay,
|
||||
args,
|
||||
cb
|
||||
};
|
||||
|
@ -57,28 +57,28 @@ function setTimer(
|
|||
dispatch.sendMsg("timers", {
|
||||
command: pb.Msg.Command.TIMER_START,
|
||||
timerStartId: timer.id,
|
||||
timerStartInterval: interval,
|
||||
timerStartDuration: duration
|
||||
timerStartInterval: timer.interval,
|
||||
timerStartDelay: timer.delay
|
||||
});
|
||||
return timer.id;
|
||||
}
|
||||
|
||||
export function setTimeout(
|
||||
cb: TimerCallback,
|
||||
duration: number,
|
||||
delay: number,
|
||||
// tslint:disable-next-line:no-any
|
||||
...args: any[]
|
||||
): number {
|
||||
return setTimer(cb, duration, false, args);
|
||||
return setTimer(cb, delay, false, args);
|
||||
}
|
||||
|
||||
export function setInterval(
|
||||
cb: TimerCallback,
|
||||
repeat: number,
|
||||
delay: number,
|
||||
// tslint:disable-next-line:no-any
|
||||
...args: any[]
|
||||
): number {
|
||||
return setTimer(cb, repeat, true, args);
|
||||
return setTimer(cb, delay, true, args);
|
||||
}
|
||||
|
||||
export function clearTimer(id: number) {
|
||||
|
|
Loading…
Reference in a new issue