@@ -29,18 +29,10 @@ globalThis.toplevel_promise_py_proxy = null;
2929
3030declare function createXeusModule ( options : any ) : any ;
3131
32- let resolveInputReply : any ;
3332let kernelReady : ( value : unknown ) => void ;
3433let rawXKernel : any ;
3534let rawXServer : any ;
3635
37- async function get_stdin ( ) {
38- const replyPromise = new Promise ( resolve => {
39- resolveInputReply = resolve ;
40- } ) ;
41- return replyPromise ;
42- }
43-
4436async function fetchJson ( url : string ) : Promise < any > {
4537 const response = await fetch ( url ) ;
4638 if ( ! response . ok ) {
@@ -50,8 +42,6 @@ async function fetchJson(url: string): Promise<any> {
5042 return json ;
5143}
5244
53- ( self as any ) . get_stdin = get_stdin ;
54-
5545globalThis . ready = new Promise ( resolve => {
5646 kernelReady = resolve ;
5747} ) ;
@@ -76,7 +66,7 @@ export class XeusWorkerLogger implements ILogger {
7666 private _channel : BroadcastChannel ;
7767}
7868
79- export class XeusRemoteKernel {
69+ export abstract class XeusRemoteKernel {
8070 constructor ( options : XeusRemoteKernel . IOptions = { } ) { }
8171
8272 async ready ( ) : Promise < void > {
@@ -116,14 +106,20 @@ export class XeusRemoteKernel {
116106 }
117107
118108 if ( msg_type === 'input_reply' ) {
119- resolveInputReply ( event . msg ) ;
109+ // Should never be called as input_reply messages are returned via service worker
120110 } else {
121111 rawXServer . notify_listener ( event . msg ) ;
122112 }
123113 }
124114
125115 async initialize ( options : IXeusWorkerKernel . IOptions ) : Promise < void > {
126- const { baseUrl, kernelSpec, empackEnvMetaLink, kernelId } = options ;
116+ const {
117+ baseUrl,
118+ browsingContextId,
119+ kernelSpec,
120+ empackEnvMetaLink,
121+ kernelId
122+ } = options ;
127123
128124 this . _logger = new XeusWorkerLogger ( kernelId ) ;
129125
@@ -210,6 +206,8 @@ export class XeusRemoteKernel {
210206 } ) ;
211207 }
212208
209+ this . _initializeStdin ( baseUrl , browsingContextId ) ;
210+
213211 rawXKernel = new globalThis . Module . xkernel ( ) ;
214212 rawXServer = rawXKernel . get_server ( ) ;
215213 if ( ! rawXServer ) {
@@ -232,6 +230,27 @@ export class XeusRemoteKernel {
232230 kernelReady ( 1 ) ;
233231 }
234232
233+ /**
234+ * Setup custom Emscripten FileSystem
235+ */
236+ abstract mount (
237+ driveName : string ,
238+ mountpoint : string ,
239+ baseUrl : string ,
240+ browsingContextId : string
241+ ) : Promise < void > ;
242+
243+ /**
244+ * Add get_stdin function to globalThis that takes an input_request message, blocks
245+ * until the corresponding input_reply is received and returns the input_reply message.
246+ * If an error occurs return an object of the form { error: "Error explanation" }
247+ * This function is called by xeus-lite's get_stdin.
248+ */
249+ protected abstract _initializeStdin (
250+ baseUrl : string ,
251+ browsingContextId : string
252+ ) : void ;
253+
235254 private _logger : XeusWorkerLogger ;
236255}
237256
0 commit comments