Recover WebWorkers

This commit is contained in:
KoalaSat 2024-03-28 23:29:27 +01:00 committed by Reckless_Satoshi
parent d8490d7530
commit 383112dc90
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
3 changed files with 20 additions and 26 deletions

View File

@ -26,10 +26,9 @@ class RoboGenerator {
const numCores = 8; const numCores = 8;
for (let i = 0; i < numCores; i++) { for (let i = 0; i < numCores; i++) {
// FIXME const worker = new Worker(new URL('./robohash.worker.ts', import.meta.url));
// const worker = new Worker(new URL('./robohash.worker.ts', import.meta.url)); worker.onmessage = this.assignTasksToWorkers.bind(this);
// worker.onmessage = this.assignTasksToWorkers.bind(this); this.workers.push({ worker, busy: false });
// this.workers.push({ worker, busy: false });
} }
} }
@ -82,8 +81,6 @@ class RoboGenerator {
hash, hash,
size, size,
) => { ) => {
// FIXME
return '';
const cacheKey = `${size}px;${hash}`; const cacheKey = `${size}px;${hash}`;
if (this.assetsCache[cacheKey]) { if (this.assetsCache[cacheKey]) {
return this.assetsCache[cacheKey]; return this.assetsCache[cacheKey];

View File

@ -1,18 +1,17 @@
// FIXME import { async_generate_robohash } from 'robo-identities-wasm';
// import { async_generate_robohash } from 'robo-identities-wasm';
// // Listen for messages from the main thread // Listen for messages from the main thread
// self.addEventListener('message', (event) => { self.addEventListener('message', (event) => {
// void (async () => { void (async () => {
// const { hash, size, cacheKey } = event.data; const { hash, size, cacheKey } = event.data;
// // Generate the image using async_image_base // Generate the image using async_image_base
// const t0 = performance.now(); const t0 = performance.now();
// const avatarB64: string = await async_generate_robohash(hash, size === 'small' ? 80 : 256); const avatarB64: string = await async_generate_robohash(hash, size === 'small' ? 80 : 256);
// const imageUrl = `data:image/png;base64,${avatarB64}`; const imageUrl = `data:image/png;base64,${avatarB64}`;
// const t1 = performance.now(); const t1 = performance.now();
// console.log(`Avatar generated in: ${t1 - t0} ms`); console.log(`Avatar generated in: ${t1 - t0} ms`);
// // Send the result back to the main thread // Send the result back to the main thread
// self.postMessage({ cacheKey, imageUrl }); self.postMessage({ cacheKey, imageUrl });
// })(); })();
// }); });

View File

@ -1,16 +1,14 @@
import { sha256 } from 'js-sha256'; import { sha256 } from 'js-sha256';
import { Robot, type Order } from '.'; import { Robot, type Order } from '.';
import { robohash } from '../components/RobotAvatar/RobohashGenerator'; import { robohash } from '../components/RobotAvatar/RobohashGenerator';
// import { generate_roboname } from 'robo-identities-wasm'; import { generate_roboname } from 'robo-identities-wasm';
class Slot { class Slot {
constructor(token: string, shortAliases: string[], robotAttributes: Record<any, any>) { constructor(token: string, shortAliases: string[], robotAttributes: Record<any, any>) {
this.token = token; this.token = token;
this.hashId = sha256(sha256(this.token)); this.hashId = sha256(sha256(this.token));
// FIXME this.nickname = generate_roboname(this.hashId);
// this.nickname = generate_roboname(this.hashId);
this.nickname = 'Robot';
// trigger RoboHash avatar generation in webworker and store in RoboHash class cache. // trigger RoboHash avatar generation in webworker and store in RoboHash class cache.
void robohash.generate(this.hashId, 'small'); void robohash.generate(this.hashId, 'small');
void robohash.generate(this.hashId, 'large'); void robohash.generate(this.hashId, 'large');