2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-29 13:27:47 +00:00

Add MsgId lock

This commit is contained in:
Dan 2018-02-13 13:59:29 +01:00
parent c6d5fb4178
commit 560991498d

View File

@ -16,6 +16,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
from threading import Lock
from time import time
@ -24,8 +25,10 @@ class MsgId:
self.delta_time = delta_time
self.last_time = 0
self.offset = 0
self.lock = Lock()
def __call__(self) -> int:
with self.lock:
now = time()
self.offset = self.offset + 4 if now == self.last_time else 0
msg_id = int((now + self.delta_time) * 2 ** 32) + self.offset