Skip to content

Commit 2e349a0

Browse files
committed
Dont use queues
1 parent 4414638 commit 2e349a0

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

core/decorators.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@
33
from discord import Embed, Color
44
from discord.ext import commands
55

6-
def queued():
7-
def decorator(coro):
8-
@functools.wraps(coro)
9-
async def wrapper(self, *args, **kwargs):
10-
await self.wait_until_ready()
11-
task = coro(self, *args, **kwargs)
12-
self._message_queue.put_nowait(task)
13-
return wrapper
14-
return decorator
156

167
async def ignore(coro):
178
try:

core/thread.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from core.models import Bot, ThreadManagerABC, ThreadABC
1111
from core.utils import is_image_url, days, match_user_id, truncate
12-
from core.decorators import ignore, queued
12+
from core.decorators import ignore
1313

1414

1515
class Thread(ThreadABC):
@@ -32,9 +32,7 @@ def __init__(self, manager: 'ThreadManager',
3232
self._recipient = recipient
3333
self._channel = channel
3434
self._ready_event = asyncio.Event()
35-
self._message_queue = asyncio.Queue()
3635
self._close_task = None
37-
self.bot.loop.create_task(self.process_messages())
3836

3937
def __repr__(self):
4038
return (f'Thread(recipient="{self.recipient or self.id}", '
@@ -75,12 +73,6 @@ def ready(self, flag):
7573
else:
7674
self._ready_event.clear()
7775

78-
async def process_messages(self):
79-
"""Guarantees order of thread messages sent"""
80-
while True:
81-
task = await self._message_queue.get()
82-
await task
83-
8476
async def setup(self, *, creator=None, category=None):
8577
"""Create the thread channel and other io related initilisation tasks"""
8678

@@ -362,7 +354,6 @@ async def reply(self, message, anonymous=False):
362354

363355
await asyncio.gather(*tasks)
364356

365-
@queued()
366357
async def send(self, message, destination=None,
367358
from_mod=False, note=False, anonymous=False):
368359
if self.close_task is not None:
@@ -380,6 +371,9 @@ async def send(self, message, destination=None,
380371
self.bot.api.append_log(message, self.channel.id)
381372
)
382373

374+
if not self.ready:
375+
self.wait_until_ready()
376+
383377
destination = destination or self.channel
384378

385379
author = message.author
@@ -500,7 +494,9 @@ async def send(self, message, destination=None,
500494

501495
await destination.send(mentions, embed=embed)
502496
if additional_images:
497+
self.ready = True
503498
await asyncio.gather(*additional_images)
499+
self.ready = False
504500

505501
if delete_message:
506502
self.bot.loop.create_task(ignore(message.delete()))

0 commit comments

Comments
 (0)