Created
February 13, 2024 18:44
-
-
Save bct/d50aa3a07320de070bdba9b21b096b2a to your computer and use it in GitHub Desktop.
jspybridge memory growth example
This file contains hidden or 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 EventEmitter = require("node:events"); | |
const emitter = new EventEmitter(); | |
const sleep = (waitTimeInMs) => | |
new Promise((resolve) => setTimeout(resolve, waitTimeInMs)); | |
async function doLoop() { | |
while (true) { | |
emitter.emit("ping", new Date().toISOString()); | |
// sleep 50ms | |
await sleep(50); | |
} | |
} | |
doLoop(); | |
module.exports = { | |
emitter, | |
}; |
This file contains hidden or 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 datetime | |
import time | |
from javascript import On, require | |
print("loading") | |
my_module = require("./test-bridge.js") | |
@On(my_module.emitter, "ping") | |
def _ping(emitter: ..., now: str): | |
print(f"pong {now} {datetime.datetime.now().time()}") | |
# Keep the Python process alive | |
time.sleep(100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment