{"result":{"depiction_url":null,"edges":{"subject":{"objects":[{"created":"2026-09-30T09:11:22Z","object_id":{"id":2555,"is_a":["categorization","keyword","keyword_information_type"],"name":"zotonic_topic_reference","title":"Reference","uri":"https:\/\/zotonic.com\/id\/2555"},"seq":1},{"created":"2026-09-30T09:11:22Z","object_id":{"id":2563,"is_a":["categorization","keyword","keyword_audience"],"name":"zotonic_topic_frontend_developer","title":"Frontend developer","uri":"https:\/\/zotonic.com\/id\/2563"},"seq":2},{"created":"2026-09-30T09:11:22Z","object_id":{"id":2673,"is_a":["categorization","keyword","keyword_technology"],"name":"zotonic_topic_javascript","title":"JavaScript","uri":"https:\/\/zotonic.com\/id\/2673"},"seq":3},{"created":"2026-09-30T09:11:22Z","object_id":{"id":2718,"is_a":["categorization","keyword","keyword_technology"],"name":"zotonic_topic_cotonic","title":"Cotonic","uri":"https:\/\/zotonic.com\/id\/2718"},"seq":4},{"created":"2026-09-30T09:11:22Z","object_id":{"id":2719,"is_a":["categorization","keyword","keyword_technology"],"name":"zotonic_topic_web_workers","title":"Web Workers","uri":"https:\/\/zotonic.com\/id\/2719"},"seq":5}],"predicate":{"id":308,"is_a":["meta","predicate"],"name":"subject","title":{"_type":"trans","tr":{"en":"Keyword"}},"uri":"http:\/\/purl.org\/dc\/elements\/1.1\/subject"}}},"id":2726,"is_a":["text","documentation","reference","cotonic_reference"],"links":[{"rel":"self","target":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/2726"},{"rel":"hub","target":"https:\/\/zotonic.com\/.zotonic\/websub"}],"medium":null,"medium_url":null,"name":"doc_cotonic_functions","page_url":{"en":"https:\/\/zotonic.com\/cotonic\/functions","x-default":"https:\/\/zotonic.com\/cotonic\/functions"},"preview_url":null,"resource":{"version":14,"pivot_location_lat":null,"title":"Page functions","is_authoritative":true,"body":"<a name=\"functions\"><\/a>\n\n            <p>\n            Cotonics main functions are available in the <tt>cotonic<\/tt> namespace on the main page.\n            The functions are mostly used to control and allow messaging between workers.\n            <\/p>\n\n            <!-- spawn -->\n            <a name=\"cotonic.spawn\"><\/a><h2>spawn <code>cotonic.spawn(url, [args])<\/code><\/h2><p>\n            Spawn a new worker. The code of the worker should be available at <tt>url<\/tt>. The optional\n            <tt>args<\/tt> parameter list will be passed to the worker and can be used to pass information from\n            the page to the worker. It can be picked up with the <a href=\"\/id\/doc_cotonic_worker_functions#worker.on_init\"><tt>on_init<\/tt><\/a>\n            callback. The structured clone algorithm will be used to send the <tt>args<\/tt> to the worker. See\n            <a href=\"\/id\/doc_cotonic_worker_functions#worker.functions\">worker functions<\/a> for more information on implementing a worker.\n            Returns the worker-id of the newly created worker process.\n            <\/p>\n            <pre>\ncotonic.spawn(&quot;\/js\/example-worker.js&quot;);\n=&gt; 1\ncotonic.spawn(&quot;\/js\/another-worker.js&quot;, [&quot;Arg1&quot;, 1]);\n=&gt; 2<\/pre>\n\n            <!-- spawn_named -->\n            <a name=\"cotonic.spawn_named\"><\/a><h2>spawn_named <code>cotonic.spawn_named(name, src_url, [base], [args])<\/code><\/h2><p>\n            Spawn a new named worker. Named workers are unique. Use <tt>&quot;&quot;<\/tt> or <tt>undefined<\/tt> to create a\n            nameless worker. Return the worker_id of the newly spawned\n            worker. If the worker was already running, the existing worker_id is returned.\n            <\/p>\n\n            <pre>\ncotonic.spawn_named(&quot;example&quot;, &quot;example-worker.js&quot;);\n=&gt; &quot;worker&quot;<\/pre>\n\n            <!-- exit -->\n            <a name=\"cotonic.exit\"><\/a><h2>exit <code>cotonic.exit(nameOrwid)<\/code><\/h2><p>\n            Exit terminates a worker which was previously spawned and has <tt>nameOrWid<\/tt> as\n        worker-id.\n            <\/p>\n\n            <pre>\nconst wid = cotonic.spawn(&quot;example.worker.js&quot;);\ncotonic.exit(wid);\n=&gt; Worker <tt>wid<\/tt> is no longer running.<\/pre>\n\n            <!-- send -->\n            <a name=\"cotonic.send\"><\/a><h2>send <code>cotonic.send(nameOrWid, message)<\/code><\/h2><p>\n            Send message <tt>message<\/tt> to worker <tt>nameOrWid<\/tt>. The parameter <tt>nameOrWid<\/tt>\n            can either be the name of worker, or a worker id. The structured clone algorithm will\n            be used to copy the <tt>message<\/tt> before sending it to the worker.\n            <\/p>\n            <pre>\ncotonic.send(worker_id1, &quot;hello&quot;);<\/pre>\n\n            <!-- receive -->\n            <a name=\"cotonic.receive\"><\/a><h2>receive <code>cotonic.receive(handler)<\/code><\/h2><p>\n            Receive messages from workers. The handler should be a function which takes\n            two parameters, the message, and the worker_id.\n            <\/p>\n            <pre>\ncotonic.receive(function(message, worker_id) {\n    console.log(&quot;Received&quot;, message, &quot;from worker&quot;, worker_id);\n});<\/pre>\n\n            <!-- configuration -->\n            <a name=\"cotonic.config\"><\/a><h2>Configuration<\/h2><p>\n            The page function has one configuration option.\n            <\/p>\n            <dl>\n                <dt><tt>base_worker_src<\/tt><\/dt>\n                <dd>The url for the base worker runtime for cotonic. This runtime provides\n                    the required communication primitives.<\/dd>\n            <\/dl>\n            <pre>\n&lt;script&gt;\n    window.cotonic = window.cotonic || {};\n    window.cotonic.config = {\n        base_worker_src: &quot;\/base\/worker-bundle.js&quot;\n    };\n&lt;\/script&gt;\n&lt;script src=&quot;cotonic.js&quot;&gt;&lt;\/script&gt;\n<\/pre>\n\n            <!-- Broker -->\n\n            ","slug":"page-functions","is_protected":false,"visible_for":0,"tz":"UTC","language":["en"],"doc_source_hash":"04adbc2abdc53f9c6acc0f92f09d541908b56fa95724cbe14df1c01fe7e82624","is_featured":false,"content_group_id":{"id":2551,"is_a":["meta","content_group"],"name":"content_group_imported_docs","title":"Imported documentation","uri":"https:\/\/zotonic.com\/id\/content_group_imported_docs"},"category_id":{"id":2722,"is_a":["meta","category"],"name":"cotonic_reference","title":"Cotonic","uri":"https:\/\/zotonic.com\/id\/cotonic_reference"},"doc_source_path":"index.html","publication_start":"2026-09-30T09:11:22Z","page_path":"\/cotonic\/functions","github_url":"https:\/\/github.com\/cotonic\/cotonic\/blob\/master\/index.html","pivot_location_lng":null,"doc_source_kind":"cotonic","name":"doc_cotonic_functions","is_unfindable":false,"is_published":true,"pivot_geocode":null,"created":"2026-09-30T09:11:22Z","uri":null,"doc_source_anchor":"functions","doc_status":"current","is_dependent":false,"publication_end":"9999-06-01T00:00:00Z","modifier_id":{"id":1,"is_a":["person"],"name":"administrator","title":"Site Administrator","uri":"https:\/\/zotonic.com\/id\/1"},"privacy":0,"doc_source_commit":"f88cc928b997d10f7f19e6bd0ede80e1c8c619bc","creator_id":{"id":1,"is_a":["person"],"name":"administrator","title":"Site Administrator","uri":"https:\/\/zotonic.com\/id\/1"},"modified":"2026-09-30T10:06:59Z","title_slug":"page-functions"},"uri":"https:\/\/zotonic.com\/id\/2726","uri_template":"https:\/\/zotonic.com\/id\/:id","websub":{"hub":"https:\/\/zotonic.com\/.zotonic\/websub","topic":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/2726"}},"status":"ok"}