-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #621 from golemfactory/chore/JST-519/add-missing-e…
…xample test(examples): add missing doc example
- Loading branch information
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
examples/docs-examples/quickstarts/retrievable-task/task.mjs
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
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(); |
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