本文整理匯總了TypeScript中rx-jupyter.kernels類的典型用法代碼示例。如果您正苦於以下問題:TypeScript kernels類的具體用法?TypeScript kernels怎麽用?TypeScript kernels使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了kernels類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: mergeMap
mergeMap(({ payload: { serverId, kernelName } }) => {
const configPath = [
"entities",
"serversById",
serverId,
"server",
"config"
];
const config = objectPath.get(state$.value, configPath);
return kernels.start(config, kernelName, "").pipe(
mergeMap(data => {
const session = uuid();
const kernel = Object.assign({}, data.response, {
channel: kernels.connect(
config,
data.response.id,
session
)
});
kernel.channel.next(kernelInfoRequest());
return merge(
of(
actions.activateKernelFulfilled({
serverId,
kernelName,
kernel
})
)
);
})
);
})
示例2: mergeMap
mergeMap(data => {
const session = data.response;
const sessionId = castToSessionId(session.id);
const kernel: RemoteKernelProps = Object.assign({}, session.kernel, {
type: "websocket",
info: null,
sessionId,
cwd,
channels: kernels.connect(
serverConfig,
session.kernel.id,
sessionId
),
kernelSpecName
});
kernel.channels.next(kernelInfoRequest());
return of(
actions.launchKernelSuccessful({
kernel,
kernelRef,
contentRef: action.payload.contentRef,
selectNextKernel: true
})
);
}),
示例3: concatMap
concatMap((action: actions.InterruptKernel) => {
const state = state$.value;
const host = selectors.currentHost(state);
if (host.type !== "jupyter") {
// Dismiss any usage that isn't targeting a jupyter server
return empty();
}
const serverConfig: ServerConfig = selectors.serverConfig(host);
const kernel = selectors.currentKernel(state);
if (!kernel) {
return of(
actions.interruptKernelFailed({
error: new Error("Can't interrupt a kernel we don't have"),
kernelRef: action.payload.kernelRef
})
);
}
if (kernel.type !== "websocket" || !kernel.id) {
return of(
actions.interruptKernelFailed({
error: new Error("Invalid kernel type for interrupting"),
kernelRef: action.payload.kernelRef
})
);
}
const id = kernel.id;
return kernels.interrupt(serverConfig, id).pipe(
map(() =>
actions.interruptKernelSuccessful({
kernelRef: action.payload.kernelRef
})
),
catchError(err =>
of(
actions.interruptKernelFailed({
error: err,
kernelRef: action.payload.kernelRef
})
)
)
);
})
示例4: checkUp
async checkUp(host: HostRecord): Promise<boolean> {
if (host.type !== UP) {
return false;
}
return kernels
.list(host.config)
.pipe(
map(xhr => {
console.log(xhr);
return true;
}),
catchError(err => {
console.error("error listing kernels on server", err);
return of(false);
})
)
.toPromise();
}
示例5: switchMap
switchMap((action: actions.ChangeKernelByName) => {
const {
payload: { contentRef, oldKernelRef, kernelSpecName }
} = action;
const state = state$.value;
const host = selectors.currentHost(state);
if (host.type !== "jupyter") {
// Dismiss any usage that isn't targeting a jupyter server
return empty();
}
const serverConfig: ServerConfig = selectors.serverConfig(host);
// TODO: This is the case where we didn't have a kernel before
// and they chose to switch kernels. Instead we need to allow
// "switching" by disregarding the previous kernel and creating a
// new session
if (!oldKernelRef) {
return empty();
}
const oldKernel = selectors.kernel(state, { kernelRef: oldKernelRef });
if (!oldKernel || oldKernel.type !== "websocket") {
return empty();
}
const { sessionId } = oldKernel;
if (!sessionId) {
return empty();
}
const content = selectors.content(state, { contentRef });
if (!content || content.type !== "notebook") {
return empty();
}
const {
filepath,
model: { notebook }
} = content;
const { cwd } = extractNewKernel(filepath, notebook);
const kernelRef = createKernelRef();
return kernels.start(serverConfig, kernelSpecName, cwd).pipe(
mergeMap(({ response }) => {
const { id: kernelId } = response;
const sessionPayload = {
kernel: { id: kernelId, name: kernelSpecName }
};
// The sessions API will close down the old kernel for us if it is
// on this session
return sessions.update(serverConfig, sessionId, sessionPayload).pipe(
mergeMap(({ response: session }) => {
const kernel: RemoteKernelProps = Object.assign(
{},
session.kernel,
{
type: "websocket",
sessionId,
cwd,
channels: kernels.connect(
serverConfig,
session.kernel.id,
sessionId
),
kernelSpecName
}
);
return of(
actions.launchKernelSuccessful({
kernel,
kernelRef,
contentRef: action.payload.contentRef,
selectNextKernel: true
})
);
}),
catchError(error =>
of(actions.launchKernelFailed({ error, kernelRef, contentRef }))
)
);
}),
catchError(error =>
of(actions.launchKernelFailed({ error, kernelRef, contentRef }))
)
);
})