mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
audio: Avoid using time.After on browsers for performance
This commit is contained in:
parent
45ca2a1f79
commit
d0778b5253
@ -430,7 +430,7 @@ func (p *Player) readToBuffer(length int) (int, error) {
|
||||
if len(r.data) > 0 {
|
||||
p.buf = append(p.buf, r.data...)
|
||||
}
|
||||
case <-time.After(15 * time.Millisecond):
|
||||
case <-timeoutIfPossible(15 * time.Millisecond):
|
||||
if l := length - len(p.buf); l > 0 {
|
||||
empty := make([]uint8, l)
|
||||
p.buf = append(p.buf, empty...)
|
||||
|
27
audio/timeout_js.go
Normal file
27
audio/timeout_js.go
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright 2017 The Ebiten Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build js
|
||||
|
||||
package audio
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func timeoutIfPossible(t time.Duration) <-chan time.Time {
|
||||
// time.After uses setTimeout and causes performance problems.
|
||||
// This function returns null and actually blocks forever.
|
||||
return nil
|
||||
}
|
25
audio/timeout_notjs.go
Normal file
25
audio/timeout_notjs.go
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2017 The Ebiten Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build !js
|
||||
|
||||
package audio
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func timeoutIfPossible(t time.Duration) <-chan time.Time {
|
||||
return time.After(t)
|
||||
}
|
Loading…
Reference in New Issue
Block a user