Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
using-worker-threads-with-konduktiva [2024/01/04 05:30] – steve.wang | using-worker-threads-with-konduktiva [2025/09/06 01:21] (current) – steve.wang | ||
---|---|---|---|
Line 3: | Line 3: | ||
**Overview: ** Sometimes running too many actions in the same nodejs thread can cause Konduktiva sequencing to be delayed because of the heavy load on the system and the single threaded nature of nodejs. To avoid this issue, we can create other threads and run heavy actions there. Reading the [[https:// | **Overview: ** Sometimes running too many actions in the same nodejs thread can cause Konduktiva sequencing to be delayed because of the heavy load on the system and the single threaded nature of nodejs. To avoid this issue, we can create other threads and run heavy actions there. Reading the [[https:// | ||
- | **Things To Note:** This tutorial assumes you have already installed Konduktiva successfully using the [[https:// | + | ** Available versions: **: Only in worker scheduler version (Steve experimental version). |
+ | **Things To Note:** This tutorial assumes you have already installed Konduktiva successfully using the [[https:// | ||
+ | <code javascript> | ||
+ | const K = require(' | ||
+ | let e = K.setUpMusicalEnvironment(K.defaultConfigurationObject, | ||
+ | </ | ||
===== giveWorkerWork ===== | ===== giveWorkerWork ===== | ||
To create a worker and make it run code use the function // | To create a worker and make it run code use the function // | ||
- | Functions have been created to allow the user to easily create and use worker threads in nodejs. These functions have been included with Konduktiva (main thread on github for now). TO explain this imagine this situation | + | Functions have been created to allow the user to easily create and use worker threads in nodejs. These functions have been included with Konduktiva (main thread on github for now). To explain |
- | For example, | + | I want the worker thread to use this function called simpleAddition and I want the worker thread to call this function passing the number //4// as an argument and return the result to the main thread: |
<code javascript> | <code javascript> | ||
function simpleAddition (a){ | function simpleAddition (a){ | ||
Line 24: | Line 29: | ||
**IMPORTANT**: | **IMPORTANT**: | ||
- | The worker thread close itself before all the code runs by using the // | + | The worker thread |
<code javascript> | <code javascript> | ||
process.exit() | process.exit() | ||
</ | </ | ||
- | //await// is needed because the // | + | //await// is needed because the // |
Here is another example which shows the worker thread using require to load a library: | Here is another example which shows the worker thread using require to load a library: | ||
Line 36: | Line 41: | ||
let testResult = await K.giveWorkerWork(requireTest) | let testResult = await K.giveWorkerWork(requireTest) | ||
</ | </ | ||
+ | |||
+ | Here is an example of adding the information given by workers to the musical environment. In this example, I will user workers to create a QuantizedMap for filterMap. The contents will be the same as chromatic. | ||
+ | <code javascript> | ||
+ | let QWorkerCode = `let {QuantizedMap} = require(' | ||
+ | let QResults = await K.giveWorkerWork(QWorkerCode) | ||
+ | e.modeFilters.sameAsChromatic = new K.QuantizedMap(QResults.keyspan, | ||
+ | </ | ||
+ | ===== Separate Repository ===== | ||
+ | |||
+ | Konduktiva still uses internal version | ||
+ | |||
+ | https:// | ||
+ | |||
+ | https:// | ||
+ | |||
+ | ===== Debugging (Not implemented yet) ===== | ||
+ | Second argument for changing behaviour of automatic removal of code files used by Worker. This is very useful for debugging because it allows user to see all the code Worker has access to and the operations worker can run. This can be done by pasting the code files used by Worker into Nodejs repl. Can help significantly with type issues (code to text and back to code) | ||
+ | |||
+ | Argument accepts strings that dictate what action is taken regarding the code files Worker uses. Argument called removal. | ||
+ | |||
+ | false: Does not remove worker code files. | ||
+ | undefined : Removes if worker exit without error but keeps if error. | ||
+ | true; Remove worker code file not matter situation. | ||
+ | |||
+ | |||
+ | [[adding-midi-file-to-musical-environment|Learn about playing midi files in Konduktiva]] |