How to use the @mathigon/boost.thread function in @mathigon/boost

To help you get started, we’ve selected a few @mathigon/boost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mathigon / textbooks / content / divisibility / functions.js View on Github external
$input.on('blur', () => {
    let v = +$input.value;
    if (!v) return $section.model.set('result', '');

    if (v > Number.MAX_SAFE_INTEGER) { $section.model.set('result', $section.getText('too-large')); return; }
    $section.model.set('result', '<span class="loading"></span>');
    $section.score('calculator');

    thread(isPrime, v)
      .then(({data}) =&gt; $section.model.set('result', $section.getText(data ? 'is-prime' : 'not-prime')))
      .catch(() =&gt; $section.model.set('result', $section.getText('no-solution')));
  });
}
github mathigon / textbooks / content / divisibility / functions.js View on Github external
$section.$('button').on('click', function() {
    let d = +$section.model.d;
    if (!d) return $section.model.set('result', '');

    $section.model.set('result', '<span class="loading"></span>');
    $section.score('calculator');

    thread(generatePrime, d, 10000)
        .then(({data}) =&gt; $section.model.set('result', numberFormat(data)))
        .catch(() =&gt; $section.model.set('result', `Couldn‘t find a prime :(`));
  });
}
github mathigon / textbooks / content / divisibility / functions.js View on Github external
$input.on('blur', () =&gt; {
    let v = +$input.value;
    if (!v) return $section.model.set('result', '');

    if (v % 2) return $section.model.set('result', $section.getText('not-even'));
    if (v &gt; Number.MAX_SAFE_INTEGER) return $section.model.set('result', $section.getText('too-large'));

    $section.model.set('result', '<span class="loading"></span>');
    $section.score('calculator');

    thread(goldbach, v, 10000)
      .then(({data}) =&gt; $section.model.set('result', `${v} = ${data[0]} + ${data[1]}`))
      .catch(() =&gt; $section.model.set('result', $section.getText('no-solution')));
  });
}
github mathigon / textbooks / content / divisibility / functions.ts View on Github external
$input.on('blur', () =&gt; {
    let v = +$input.value;
    if (!v) return $section.model.set('result', '');

    if (v % 2) return $section.model.set('result',
        $section.getText('not-even'));
    if (v &gt; Number.MAX_SAFE_INTEGER) return $section.model.set('result',
        $section.getText('too-large'));

    $section.model.set('result', '<span class="loading"></span>');
    $section.score('calculator');

    thread('/resources/divisibility/worker.js', ['goldbach', v], 10000)
        .then(result =&gt; $section.model.set('result',
            `${v} = ${result![0]} + ${result![1]}`))
        .catch(() =&gt; $section.model.set('result',
            $section.getText('no-solution')));
  });
}
github mathigon / textbooks / content / divisibility / functions.ts View on Github external
$input.on('blur', () =&gt; {
    let v = +$input.value;
    if (!v) return $section.model.set('result', '');

    if (v &gt; Number.MAX_SAFE_INTEGER) {
      $section.model.set('result', $section.getText('too-large'));
      return;
    }
    $section.model.set('result', '<span class="loading"></span>');
    $section.score('calculator');

    thread('/resources/divisibility/worker.js', ['isPrime', v])
        .then(result =&gt; $section.model.set('result',
            $section.getText(result ? 'is-prime' : 'not-prime')))
        .catch(() =&gt; $section.model.set('result',
            $section.getText('no-solution')));
  });
}