Scott Baker | bef5fd9 | 2019-02-21 10:24:02 -0800 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2017 the original author or authors. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
Zack Williams | 5c2ea23 | 2019-01-30 15:23:01 -0700 | [diff] [blame] | 16 | from __future__ import absolute_import |
Scott Baker | bef5fd9 | 2019-02-21 10:24:02 -0800 | [diff] [blame] | 17 | from twisted.internet import reactor |
| 18 | from twisted.internet.defer import Deferred |
| 19 | |
| 20 | |
| 21 | def asleep(dt): |
| 22 | """ |
| 23 | Async (event driven) wait for given time period (in seconds) |
| 24 | :param dt: Delay in seconds |
| 25 | :return: Deferred to be fired with value None when time expires. |
| 26 | """ |
| 27 | d = Deferred() |
| 28 | reactor.callLater(dt, lambda: d.callback(None)) |
Zack Williams | 5c2ea23 | 2019-01-30 15:23:01 -0700 | [diff] [blame] | 29 | return d |