dcp-client 4.4.9-0 → 4.4.10-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,66 +0,0 @@
1
- #! /usr/bin/env node
2
-
3
- /**
4
- * Deploy a job using URL for the work function
5
- * work function should be defined and sent on the wire as a string.
6
- * Note that to allow workers fetch the work function from URL,
7
- * - in the browser worker: in the console run `worker.allowOrigins.any.push('http://localhost:12347')`
8
- * - in the node worker: add `-a 'http://localhost:12347'` at the end of starting worker command
9
- */
10
- const SCHEDULER_URL = new URL('https://scheduler.distributed.computer');
11
- const express = require('express');
12
-
13
- /** Main program entry point */
14
- async function main() {
15
- const compute = require('dcp/compute');
16
-
17
- const app = express();
18
- const port = 12347;
19
- app.get('/', (req, res) => {
20
- let workerFunction = `async function(c){
21
- let sum = 0;
22
- for (let i = 0; i < 10000000; i += 1) {
23
- progress(i / 10000000);
24
- sum += Math.random();
25
- }
26
- return c;
27
- }`
28
- res.send(workerFunction);
29
- })
30
- app.listen(port, () => {
31
- console.log(`port ${port} is ready!`);
32
- })
33
-
34
- let dcp_workFunction_url = new URL(`http://localhost:${port}/`)
35
-
36
- const job = compute.for(
37
- ['hello','world'],
38
- dcp_workFunction_url,
39
- );
40
-
41
- job.on('accepted', () => {
42
- console.log(` - Job accepted by scheduler, waiting for results`);
43
- console.log(` - Job has id ${job.id}`);
44
- });
45
-
46
- job.on('readystatechange', (arg) => {
47
- console.log(`new ready state: ${arg}`);
48
- });
49
-
50
- job.on('result', (ev) => {
51
- console.log(ev);
52
- });
53
-
54
- job.public.name = 'URL-workFunction-example';
55
-
56
- const results = await job.exec(0.0000001);
57
- console.log('results=', Array.from(results));
58
- }
59
-
60
- /* Initialize DCP Client and run main() */
61
- require('../..')
62
- .init(SCHEDULER_URL)
63
- .then(main)
64
- .catch(console.error)
65
- .finally(process.exit);
66
-