Skip to content

Commit

Permalink
Merge pull request #621 from golemfactory/chore/JST-519/add-missing-e…
Browse files Browse the repository at this point in the history
…xample

test(examples): add missing doc example
  • Loading branch information
cryptobench authored Oct 19, 2023
2 parents 012c95e + 72b7042 commit e7ac9e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
23 changes: 23 additions & 0 deletions examples/docs-examples/quickstarts/retrievable-task/task.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { GolemNetwork, JobState } from "@golem-sdk/golem-js";

const golem = new GolemNetwork({
yagnaOptions: { apiKey: "try_golem" },
});
await golem.init();
const job = await golem.createJob(async (ctx) => {
const response = await ctx.run("echo 'Hello, Golem!'");
return response.stdout;
});

let state = await job.fetchState();
while (state === JobState.Pending || state === JobState.New) {
console.log("Job is still running...");
await new Promise((resolve) => setTimeout(resolve, 1000));
state = await job.fetchState();
}

console.log("Job finished with state:", state);
const result = await job.fetchResults();
console.log("Job results:", result);

await golem.close();
1 change: 1 addition & 0 deletions tests/examples/examples.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[
{ "cmd": "node", "path": "examples/docs-examples/quickstarts/retrievable-task/task.mjs", "noGoth": true },
{ "cmd": "node", "path": "examples/docs-examples/examples/composing-tasks/batch-end.mjs", "noGoth": true },
{
"cmd": "node",
Expand Down

0 comments on commit e7ac9e9

Please sign in to comment.