Shaka Player Embedded
timeouts.cc
Go to the documentation of this file.
1 // Copyright 2016 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/js/timeouts.h"
16 
17 #include <algorithm>
18 #include <utility>
19 
21 #include "src/mapping/js_utils.h"
23 
24 namespace shaka {
25 namespace js {
26 
27 // The minimum delay (in milliseconds) that a timer can be set to.
28 constexpr const uint64_t kMinTimerDelay = 4;
29 
35 }
36 
38  const uint64_t real_timeout = std::max(timeout.value_or(0), kMinTimerDelay);
39  RefPtr<Callback> cb = MakeJsRef<Callback>(std::move(callback));
40  return JsManagerImpl::Instance()->MainThread()->AddTimer(real_timeout,
41  [=]() { (*cb)(); });
42 }
43 
45  const uint64_t real_timeout = std::max(timeout.value_or(0), kMinTimerDelay);
46  RefPtr<Callback> cb = MakeJsRef<Callback>(std::move(callback));
48  real_timeout, [=]() { (*cb)(); });
49 }
50 
52  if (id.has_value())
54 }
55 
57  if (id.has_value())
59 }
60 
61 } // namespace js
62 } // namespace shaka
static void ClearTimeout(optional< int > id)
Definition: timeouts.cc:51
static void ClearInterval(optional< int > id)
Definition: timeouts.cc:56
static int SetInterval(Callback callback, optional< uint64_t > timeout)
Definition: timeouts.cc:44
void CancelTimer(int id)
Definition: task_runner.cc:94
constexpr const uint64_t kMinTimerDelay
Definition: timeouts.cc:28
static int SetTimeout(Callback callback, optional< uint64_t > timeout)
Definition: timeouts.cc:37
int AddTimer(uint64_t delay_ms, Func &&callback)
Definition: task_runner.h:243
T value_or(U &&default_value) const &
Definition: optional.h:165
int AddRepeatedTimer(uint64_t delay_ms, Func &&callback)
Definition: task_runner.h:267
void RegisterGlobalFunction(const std::string &name, Func &&callback)
static void Install()
Definition: timeouts.cc:30
TaskRunner * MainThread()