MCPcopy Index your code
hub / github.com/gpujs/gpu.js / kernelRunShortcut

Function kernelRunShortcut

src/kernel-run-shortcut.js:8–52  ·  view source on GitHub ↗

* Makes kernels easier for mortals (including me) * @param kernel * @returns {function()}

(kernel)

Source from the content-addressed store, hash-verified

6 * @returns {function()}
7 */
8function kernelRunShortcut(kernel) {
9 let run = function() {
10 kernel.build.apply(kernel, arguments);
11 run = function() {
12 let result = kernel.run.apply(kernel, arguments);
13 if (kernel.switchingKernels) {
14 const reasons = kernel.resetSwitchingKernels();
15 const newKernel = kernel.onRequestSwitchKernel(reasons, arguments, kernel);
16 shortcut.kernel = kernel = newKernel;
17 result = newKernel.run.apply(newKernel, arguments);
18 }
19 if (kernel.renderKernels) {
20 return kernel.renderKernels();
21 } else if (kernel.renderOutput) {
22 return kernel.renderOutput();
23 } else {
24 return result;
25 }
26 };
27 return run.apply(kernel, arguments);
28 };
29 const shortcut = function() {
30 return run.apply(kernel, arguments);
31 };
32 /**
33 * Run kernel in async mode
34 * @returns {Promise<KernelOutput>}
35 */
36 shortcut.exec = function() {
37 return new Promise((accept, reject) => {
38 try {
39 accept(run.apply(this, arguments));
40 } catch (e) {
41 reject(e);
42 }
43 });
44 };
45 shortcut.replaceKernel = function(replacementKernel) {
46 kernel = replacementKernel;
47 bindKernelToShortcut(kernel, shortcut);
48 };
49
50 bindKernelToShortcut(kernel, shortcut);
51 return shortcut;
52}
53
54function bindKernelToShortcut(kernel, shortcut) {
55 if (shortcut.kernel) {

Callers 1

createKernelMethod · 0.85

Calls 1

bindKernelToShortcutFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…