codekingpro/portable-devtools
114k
1# Copyright 2016 Étienne Bersac2# Copyright 2016 Julien Danjou3# Copyright 2016 Joshua Harlow4# Copyright 2013-2014 Ray Holder5#6# Licensed under the Apache License, Version 2.0 (the "License");7# you may not use this file except in compliance with the License.8# You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing, software13# distributed under the License is distributed on an "AS IS" BASIS,14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15# See the License for the specific language governing permissions and16# limitations under the License.17 18import time19import typing20 21if typing.TYPE_CHECKING:22 import threading23 24 25def sleep(seconds: float) -> None:26 """27 Sleep strategy that delays execution for a given number of seconds.28 29 This is the default strategy, and may be mocked out for unit testing.30 """31 time.sleep(seconds)32 33 34class sleep_using_event:35 """Sleep strategy that waits on an event to be set."""36 37 def __init__(self, event: "threading.Event") -> None:38 self.event = event39 40 def __call__(self, timeout: typing.Optional[float]) -> None:41 # NOTE(harlowja): this may *not* actually wait for timeout42 # seconds if the event is set (ie this may eject out early).43 self.event.wait(timeout=timeout)44 