import { t as debug_default } from "./debug-BT60qQj9.js";
import fastq from "fastq";
//#region src/messengers/memory_queue.ts
/**
* Worker to send emails
*/
function sendEmail(task, cb) {
	this.mailer.sendCompiled(task.mail, task.sendConfig).then((result) => cb(null, result)).catch((error) => cb(error));
}
/**
* Memory queue messenger uses "fastq" npm package to keep
* emails within memory and send them in the chunks of 10
*/
var MemoryQueueMessenger = class {
	mailer;
	#emitter;
	#queue = fastq(this, sendEmail, 10);
	#jobCompletedCallback = (error) => {
		if (error) this.#emitter.emit("queued:mail:error", {
			error,
			mailerName: this.mailer.name
		});
	};
	constructor(mailer, emitter) {
		this.mailer = mailer;
		this.#emitter = emitter;
	}
	/**
	* Queues the email within memory
	*/
	async queue(mail, sendConfig) {
		debug_default("pushing email to in-memory queue");
		this.#queue.push({
			mail,
			sendConfig
		}, this.#jobCompletedCallback);
	}
};
//#endregion
export { MemoryQueueMessenger as t };
