From 2e57ad881cde0e0ce50b7de9038ae2bfa61861b6 Mon Sep 17 00:00:00 2001 From: fdemir Date: Mon, 11 Jul 2022 02:07:21 +0300 Subject: [PATCH] :sparkles: add listen callback funciton --- lib/bao.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/bao.ts b/lib/bao.ts index 746d89a..a0053bf 100644 --- a/lib/bao.ts +++ b/lib/bao.ts @@ -104,10 +104,17 @@ export default class Bao { * Start the server on the specified port * * @param options The options for the server + * @param callback The callback function to be run when the server is started * @returns A Bun Server object */ - listen(options: IListen = {}): Server { - return Bun.serve(this.#serve(options)); + listen(options: IListen = {}, callback?: () => void): Server { + const server = Bun.serve(this.#serve(options)); + + if (server && callback) { + callback(); + } + + return server; } #serve(listen: IListen): Serve {