-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tasks #138
Comments
I am very interested in using SDK-ts with a distributed network, I'd love to help you test things out here, I'm just not sure where to start. I would like to use the SDK in Bun, Nodejs, browsers and web workers. (I don't have a resonate server running ) |
Hey James, you can take a look at some of the examples, currently the sdk works both with Nodejs and Bun (Probably Deno too, he haven't tested out) but does not work in the Browser. You can definitely use the sdk without a server, said that, spinning out a server should be very simple, You can follow the instructions here https://docs.resonatehq.io/resonate/overview More info about the SDK: https://docs.resonatehq.io/sdks/typescript |
Actually it work fine in Chrome at least, paste this in the console: const { Resonate, Context } = await import('https://esm.run/@resonatehq/[email protected]')
async function downloadAndSummarize(context, url) {
console.log('downloadAndSummarize: main function-')
// Download the content from the provided URL
let content = await context.run(download, url);
// Summarize the downloaded content
let summary = await context.run(summarize, content);
// Return the summary of the content
return summary;
}
async function download(context, url) {
console.log('download: function-')
return new Promise((resolve, reject) => {
setTimeout(() => {
if (Math.random() < 0.95) { // 10% chance to fail
console.log('oops, download failed!')
reject("download failed");
} else {
resolve("This is the text of the page");
}
}, 2500);
})
}
async function summarize(context, text) {
console.log('summarize: function-')
return new Promise((resolve, reject) => {
setTimeout(() => {
if (Math.random() < 0.85) { // 10% chance to fail
reject("summarize failed");
} else {
resolve("This is a summary of the text");
}
}, 2500);
});
}
const resonate = new Resonate();
// resonate.start();
resonate.register("downloadAndSummarize",
downloadAndSummarize,
{ timeout: 120000 }
);
resonate.start()
console.log('running runDownloadAndSummarize', this.resonate)
let summary = await resonate.run("downloadAndSummarize", /* id */ `summarize-abc`, /* param */ 'abc').catch(console.error);
console.log('summary', summary ) |
My idea is to implement a RemoteStore to pass to SDK that connects with websockets to a distributed network of. |
Depending on what you want Resonate to do for you it might or might not have to do with this issue. You can currently implement your own store. how ever the Resonate server does not support web sockets. To talk between different Resonate nodes Tasks might be the solutions, we are still in design phase for it, but as of now, we will still go through the server, but probably in a more generic way than just http. |
Both the SDK and the Resonate server are converging in what we now call tasks.
There are two types of tasks that represent the events of the global event loop,
Resume
andInvoke
.Resume
event signals a Resonate node that a promise the node was awaiting on hasbeen completed and the node can resume work where it left off.
Invoke
event signal a Resonate node to invoke a function in its local executioncontext and report back its results.
Considerations
come as an http request, messages in distributed queue system like SQS or be polled
by the SDK itself from the server.
way that is compatible with the rest of the Resonate architecture like the server
communication.
running.
The text was updated successfully, but these errors were encountered: