1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00

fix all duration to delay with mdn description

This commit is contained in:
Yorkie Liu 2018-06-01 02:26:43 +08:00 committed by Ryan Dahl
parent 38a2c042b6
commit 84b0687990
2 changed files with 14 additions and 14 deletions

View file

@ -12,7 +12,7 @@ type Timer struct {
Done bool Done bool
Cleared bool Cleared bool
Interval bool Interval bool
Duration int32 // In milliseconds Delay int32 // In milliseconds
} }
var timers = make(map[int32]*Timer) var timers = make(map[int32]*Timer)
@ -28,11 +28,11 @@ func InitTimers() {
Id: id, Id: id,
Done: false, Done: false,
Interval: msg.TimerStartInterval, Interval: msg.TimerStartInterval,
Duration: msg.TimerStartDuration, Delay: msg.TimerStartDelay,
Cleared: false, Cleared: false,
} }
if t.Duration < 10 { if t.Delay < 10 {
t.Duration = 10 t.Delay = 10
} }
t.StartTimer() t.StartTimer()
timers[id] = t timers[id] = t
@ -62,7 +62,7 @@ func (t *Timer) StartTimer() {
go func() { go func() {
defer t.Clear() defer t.Clear()
for { for {
time.Sleep(time.Duration(t.Duration) * time.Millisecond) time.Sleep(time.Duration(t.Delay) * time.Millisecond)
if !t.Interval { if !t.Interval {
t.Done = true t.Done = true
} }

View file

@ -15,7 +15,7 @@ interface Timer {
interval: boolean; interval: boolean;
// tslint:disable-next-line:no-any // tslint:disable-next-line:no-any
args: any[]; args: any[];
duration: number; // milliseconds delay: number; // milliseconds
} }
const timers = new Map<number, Timer>(); const timers = new Map<number, Timer>();
@ -41,7 +41,7 @@ function onMessage(payload: Uint8Array) {
function setTimer( function setTimer(
cb: TimerCallback, cb: TimerCallback,
duration: number, delay: number,
interval: boolean, interval: boolean,
// tslint:disable-next-line:no-any // tslint:disable-next-line:no-any
args: any[] args: any[]
@ -49,7 +49,7 @@ function setTimer(
const timer = { const timer = {
id: nextTimerId++, id: nextTimerId++,
interval, interval,
duration, delay,
args, args,
cb cb
}; };
@ -57,28 +57,28 @@ function setTimer(
dispatch.sendMsg("timers", { dispatch.sendMsg("timers", {
command: pb.Msg.Command.TIMER_START, command: pb.Msg.Command.TIMER_START,
timerStartId: timer.id, timerStartId: timer.id,
timerStartInterval: interval, timerStartInterval: timer.interval,
timerStartDuration: duration timerStartDelay: timer.delay
}); });
return timer.id; return timer.id;
} }
export function setTimeout( export function setTimeout(
cb: TimerCallback, cb: TimerCallback,
duration: number, delay: number,
// tslint:disable-next-line:no-any // tslint:disable-next-line:no-any
...args: any[] ...args: any[]
): number { ): number {
return setTimer(cb, duration, false, args); return setTimer(cb, delay, false, args);
} }
export function setInterval( export function setInterval(
cb: TimerCallback, cb: TimerCallback,
repeat: number, delay: number,
// tslint:disable-next-line:no-any // tslint:disable-next-line:no-any
...args: any[] ...args: any[]
): number { ): number {
return setTimer(cb, repeat, true, args); return setTimer(cb, delay, true, args);
} }
export function clearTimer(id: number) { export function clearTimer(id: number) {