MCPcopy
hub / github.com/midrender/revideo / threads

Function threads

packages/core/src/threading/threads.ts:56–109  ·  view source on GitHub ↗
(
  factory: ThreadsFactory,
  callback?: ThreadsCallback,
)

Source from the content-addressed store, hash-verified

54 * Used for debugging purposes.
55 */
56export function* threads(
57 factory: ThreadsFactory,
58 callback?: ThreadsCallback,
59): ThreadGenerator {
60 const playback = usePlayback();
61 const root = factory();
62 setTaskName(root, 'root');
63 const rootThread = new Thread(root);
64 callback?.(rootThread);
65
66 let threads: Thread[] = [rootThread];
67 while (threads.length > 0) {
68 const newThreads = [];
69 const queue = [...threads];
70 const dt = playback.deltaTime;
71
72 while (queue.length > 0) {
73 const thread = queue.pop();
74 if (!thread || thread.canceled) {
75 continue;
76 }
77
78 const result = thread.next();
79 if (result.done) {
80 thread.cancel();
81 continue;
82 }
83
84 if (isThreadGenerator(result.value)) {
85 const child = new Thread(result.value);
86 thread.value = result.value;
87 thread.add(child);
88
89 queue.push(thread);
90 queue.push(child);
91 } else if (result.value) {
92 thread.value = yield result.value;
93 queue.push(thread);
94 } else {
95 thread.update(dt);
96 thread.drain(task => {
97 const child = new Thread(task);
98 thread.add(child);
99 newThreads.unshift(child);
100 });
101
102 newThreads.unshift(thread);
103 }
104 }
105
106 threads = newThreads.filter(thread => !thread.canceled);
107 if (threads.length > 0) yield;
108 }
109}

Callers 8

generatorTestFunction · 0.90
join.test.tsFile · 0.90
scheduling.test.tsFile · 0.90
resetFunction · 0.90
tween.test.tsFile · 0.90
spring.test.tsFile · 0.90
threads.test.tsFile · 0.90
cancel.test.tsFile · 0.90

Calls 8

usePlaybackFunction · 0.90
setTaskNameFunction · 0.90
isThreadGeneratorFunction · 0.90
cancelMethod · 0.80
drainMethod · 0.80
nextMethod · 0.65
addMethod · 0.65
updateMethod · 0.45

Tested by 1

generatorTestFunction · 0.72