2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 12:57:52 +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,11 +25,13 @@ class MsgId:
self.delta_time = delta_time
self.last_time = 0
self.offset = 0
self.lock = Lock()
def __call__(self) -> int:
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
self.last_time = now
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
self.last_time = now
return msg_id
return msg_id