DrSensor / nusa

(status: REWRITING it into different project) incremental runtime that bring both simplicity and power into webdev (buildless, cross-language, data-driven)
MIT License
4 stars 0 forks source link

Option to run module in Worker thread #33

Open DrSensor opened 2 years ago

DrSensor commented 2 years ago
<link :worker href=mod.js>
<link shared:worker href=crosstab.js>

<link :worker=threadA href=modA1.js>
<link :worker=threadA href=modA2.js media=(min-width: 320px)>

<link :worker=threadB href=modB1.js>
<link :worker=threadB href=modB2.js>

<link shared:worker=threadA href=crosstabA.js>
<link shared:worker=threadA href=crosstabA.js>

<link shared:worker=threadC href=modC.js>
<link shared:worker=threadC href=modC.js>
DrSensor commented 1 year ago
/** @path ./nusa/current/thread.js */

export let /** @type number */ count

export let /** @type string */ name
/** @path ./nusa/current.js */

import * as w from "./current/worker.js"

export const worker = {
  get count() { return w.count },
  get name() { return w.name },

  /** @example ```js
  for ( // auto-cast as count number
    let i = (data.length / current.worker) - 1;
    i !== 0; i--
  ) {
    // heavy computation
  }

  // auto-cast as name string
  console.debug(`thread ${current.worker}`)
  ```*/
  [Symbol.toPrimitive](type) {
    switch (type) {
      case "number": return w.count
      case "string": return w.name
      default: throw "loose equal operator (==) is ambiguous"
    }
  },
}