From c688886d714733ada0cf498b541e4dbd134e0cb7 Mon Sep 17 00:00:00 2001 From: sunshinesmilelk <1176136681@qq.com> Date: Mon, 5 Feb 2024 13:28:11 +0800 Subject: [PATCH] feat(kernel): add startNew in LibroKernelManager --- .../src/kernel/libro-kernel-manager.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/packages/libro-kernel/src/kernel/libro-kernel-manager.ts b/packages/libro-kernel/src/kernel/libro-kernel-manager.ts index bb5b763f..a70c34e5 100644 --- a/packages/libro-kernel/src/kernel/libro-kernel-manager.ts +++ b/packages/libro-kernel/src/kernel/libro-kernel-manager.ts @@ -19,6 +19,7 @@ import { LibroKernelConnectionFactory, } from './libro-kernel-protocol.js'; import type { LibroKernel } from './libro-kernel.js'; +import type { IKernelOptions } from './restapi.js'; import { KernelRestAPI } from './restapi.js'; @singleton() @@ -96,6 +97,29 @@ export class LibroKernelManager { return this._ready; } + /** + * Start a new kernel. + * + * @param createOptions - The kernel creation options + * + * @param connectOptions - The kernel connection options + * + * @returns A promise that resolves with the kernel connection. + * + * #### Notes + * The manager `serverSettings` will be always be used. + */ + async startNew( + createOptions: IKernelOptions = {}, + connectOptions: Omit = {}, + ): Promise { + const model = await this.kernelRestAPI.startNew(createOptions); + return this.connectToKernel({ + ...connectOptions, + model, + }); + } + /** * A signal emitted when the running kernels change. */