Last active
April 18, 2020 14:36
-
-
Save cmonacaps/2dd39d9b3d7d9b2306b7dd5812484b84 to your computer and use it in GitHub Desktop.
exception presentation fails when actual error is lost, possibly during threadsjs post-error-to-window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const App = () => ( | |
<Worker> | |
{props => ( | |
<ErrorBoundary {...props}> | |
<Juicy> | |
<ApplicationComponents /> | |
</Juicy> | |
</ErrorBoundary> | |
)} | |
</Worker> | |
); | |
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { isNil, transpose } from 'ramda'; | |
import styles from './ErrorBoundary.module.css'; | |
class ErrorBoundary extends React.Component { | |
state = { | |
error: null, | |
info: null, | |
}; | |
componentDidCatch(error, info) { | |
this.setState({ error, info }); | |
// maybe I should do something here to swallow it? | |
} | |
render() { | |
const { error } = this.state; | |
if (isNil(error)) { | |
return <>{this.props.children}</>; | |
} else if (typeof error === 'string') { | |
// I'm not sure if this is correct or even if this case happens | |
// I think all the time it's doing the isNil case if there's no | |
// error, just above, or the render case if there's an error, | |
// just below | |
return [`${error}`]; | |
} else { | |
const [heading, ...stack] = (error => { | |
// bunch of string array maps mishmash | |
return mishmash; | |
})(error); | |
return ( | |
<div className={styles.errorScreen}> | |
{/* bunch of flexbox */} | |
</div> | |
); | |
} | |
} | |
} | |
export default ErrorBoundary; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { spawn, Thread, Worker } from 'threads'; | |
/** | |
* WorkerManager - an owner of workers, that supplies their entries via props | |
* | |
*/ | |
class WorkerManager extends React.PureComponent { | |
constructor(props) { | |
super(props); | |
this.state = { workers: null }; | |
} | |
componentDidMount() { | |
Promise.all([ | |
spawn(new Worker('./workerOps')), | |
// .. spawn is repeated | |
]).then((workers) => | |
this.setState({ | |
workers, | |
}) | |
); | |
} | |
componentWillUnmount() { | |
const waitWorkerTerm = async () => | |
await Promise.all( | |
this.state.workers.map((worker) => | |
worker ? Thread.terminate(worker) : null | |
) | |
); | |
waitWorkerTerm(); | |
} | |
render() { | |
return ( | |
<> | |
{this.props.children({ | |
// makeOpsMapping, elided, produces like, | |
// { reticulateSplines, findTheCourageToLoveAgain, ... } | |
workerOps: makeOpsMapping(this.state.workers ?? []), | |
...this.props, | |
})} | |
</> | |
); | |
} | |
} | |
export default WorkerManager; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment