Skip to content

Instantly share code, notes, and snippets.

@captainsafia
Last active January 15, 2020 00:10
Show Gist options
  • Save captainsafia/3a0e1fb2f436683ae44fe953694c64c9 to your computer and use it in GitHub Desktop.
Save captainsafia/3a0e1fb2f436683ae44fe953694c64c9 to your computer and use it in GitHub Desktop.
export const updateDisplayEpic = (
action$: ActionsObservable<
actions.NewKernelAction | actions.KillKernelSuccessful
>
) =>
// Global message watcher so we need to set up a feed for each new kernel
action$.pipe(
ofType(actions.LAUNCH_KERNEL_SUCCESSFUL),
switchMap(
(action: actions.NewKernelAction | actions.KillKernelSuccessful) =>
(action as actions.NewKernelAction).payload.kernel.channels.pipe(
map((msg: JupyterMessage) => ({ type: "KERNEL_MESSAGE", payload: { msg } }))),
catchError(error =>
console.log(error) // Wait some time and launch the kernel
)
)
)
);
/**
* Listens to unexpected closes on the WebSocket subject connecting
* to the client to the service then notifies the user and triggers
* a kernel restart.
*/
const watchKernelFailure = (
action$: ActionsObservable<nteractActions.NewKernelAction>,
state$: any
) =>
action$.pipe(
ofType(nteractActions.LAUNCH_KERNEL_SUCCESSFUL),
withLatestFrom(state$),
switchMap(([action, state]) =>
action.payload.kernel.channels.pipe(
last(),
mergeMap(() => {
const kernel = selectors.kernelForContentRef(action.payload.contentRef);
return of(launchkernelHere);
}),
takeUntil(action$.pipe(ofType(nteractActions.KILL_KERNEL_SUCCESSFUL)))
)
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment