UNPKG

dcp-client

Version:

Core libraries for accessing DCP network

54 lines (50 loc) 1.64 kB
/** * This file registers the map-basic worktime for DCP. The map-basic worktime is * the default worktime used with compute.for, compute.do, etc... * * Copyright (c) 2018-2024, Distributive, Ltd. All Rights Reserved. * @author Severn Lortie <severn@distributive.network> */ // @ts-nocheck self.wrapScriptLoading({ scriptName: 'map-basic-worktime' }, function mapBasicWorktime$$fn(protectedStorage, ring1PostMessage, wrapPostMessage) { let workFunction; let workFunctionArguments; /** * Registers the worktime callbacks that allow the worktime controller (worktimes.js) to setup our environment and run the worktime */ function registerWorktime() { protectedStorage.worktimes.registerWorktime({ name: 'map-basic', version: '1.0.0', initSandbox, processSlice, }); } /** * Perform setup tasks before processSlice is run * @param {object} job The job assigned to this sandbox */ function initSandbox(job) { workFunctionArguments = job.arguments; workFunctionArguments.unshift(false); const indirectEval = eval; if (job.useStrict) workFunction = indirectEval(`"use strict"; (${job.workFunction})`); else workFunction = indirectEval(`(${job.workFunction})`); } /** * The processSlice hook function which runs the work function for input slice data * @param {*} data The slice data * @returns {*} The slice result */ async function processSlice(data) { workFunctionArguments[0] = data; const result = await workFunction.apply(null, workFunctionArguments); return result; } registerWorktime(); });