Skip to content

Instantly share code, notes, and snippets.

@rotemmiz
Last active January 2, 2017 16:10
Show Gist options
  • Save rotemmiz/6d17e3f6a708a246a680a0513a0d9433 to your computer and use it in GitHub Desktop.
Save rotemmiz/6d17e3f6a708a246a680a0513a0d9433 to your computer and use it in GitHub Desktop.
[RN] Busy JS thread example
class SearchBar extends React.Component {
render() {
...
return (
...
<TouchableOpacity onPress={this.actBusy.bind(this)}>
<View style={styles.button}>
<Text>Spam mqt_js</Text>
</View>
</TouchableOpacity>
<TouchableOpacity onPress={this.spamBridge.bind(this)}>
<View style={styles.button}>
<Text>Spam bridge</Text>
</View>
</TouchableOpacity>
...
);
}
// make mqt_js super busy
actBusy() {
setTimeout(() => { this.actBusyFor(8000); }, 500);
}
actBusyFor(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds) {
break;
}
}
}
spamBridge() {
for (var i = 0; i < 1000; i++) {
this.initTimer();
}
}
// setTimeout sends a message over MessageQueue.js to trigger the Native "Timing.createTimer()"
initTimer() {
const that = this;
setTimeout(function() {
that.initTimer();
}, 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment