Skip to content

Commit

Permalink
fix all duration to delay with mdn description
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkie authored and ry committed May 31, 2018
1 parent 38a2c04 commit 84b0687
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions timers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
18 changes: 9 additions & 9 deletions timers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand All @@ -41,44 +41,44 @@ function onMessage(payload: Uint8Array) {

function setTimer(
cb: TimerCallback,
duration: number,
delay: number,
interval: boolean,
// tslint:disable-next-line:no-any
args: any[]
): number {
const timer = {
id: nextTimerId++,
interval,
duration,
delay,
args,
cb
};
timers.set(timer.id, timer);
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) {
Expand Down

0 comments on commit 84b0687

Please sign in to comment.