mirror of
https://github.com/pyrogram/pyrogram
synced 2025-08-29 13:27:47 +00:00
Add MsgId lock
This commit is contained in:
parent
c6d5fb4178
commit
560991498d
@ -16,6 +16,7 @@
|
|||||||
# You should have received a copy of the GNU Lesser General Public License
|
# You should have received a copy of the GNU Lesser General Public License
|
||||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from threading import Lock
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
|
|
||||||
@ -24,8 +25,10 @@ class MsgId:
|
|||||||
self.delta_time = delta_time
|
self.delta_time = delta_time
|
||||||
self.last_time = 0
|
self.last_time = 0
|
||||||
self.offset = 0
|
self.offset = 0
|
||||||
|
self.lock = Lock()
|
||||||
|
|
||||||
def __call__(self) -> int:
|
def __call__(self) -> int:
|
||||||
|
with self.lock:
|
||||||
now = time()
|
now = time()
|
||||||
self.offset = self.offset + 4 if now == self.last_time else 0
|
self.offset = self.offset + 4 if now == self.last_time else 0
|
||||||
msg_id = int((now + self.delta_time) * 2 ** 32) + self.offset
|
msg_id = int((now + self.delta_time) * 2 ** 32) + self.offset
|
||||||
|
Loading…
x
Reference in New Issue
Block a user