Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-dcp-worker

Package Overview
Dependencies
Maintainers
2
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-dcp-worker - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

63

lib/useDCPWorker.js

@@ -46,6 +46,6 @@ "use strict";

}
else if (action.type === 'SUBMIT_TRUE') {
else if (action.type === 'SUBMITTING_TRUE') {
updatedState.submitting = true;
}
else if (action.type === 'SUBMIT_FALSE') {
else if (action.type === 'SUBMITTING_FALSE') {
updatedState.fetching = false;

@@ -362,5 +362,3 @@ }

dcpWorker.on('sandbox', (sandbox) => {
let lastStarted = NaN;
const onStart = () => {
lastStarted = Date.now();
sandbox.on('slice', () => {
dispatchWorkerState({

@@ -370,36 +368,27 @@ type: 'SET_WORKING_SANDBOXES',

});
};
const onFinish = () => {
const timeSpent = Date.now() - lastStarted;
lastStarted = NaN;
if (isFinite(timeSpent))
dispatchWorkerStats({
type: 'INCREMENT_COMPUTE_TIME',
data: timeSpent,
});
dispatchWorkerState({
type: 'SET_WORKING_SANDBOXES',
data: dcpWorker.workingSandboxes.length,
});
sandbox.on('metrics', (_, measurements) => {
dispatchWorkerStats({
type: 'INCREMENT_COMPUTE_TIME',
data: measurements.elapsed, // seconds
});
};
sandbox.on('start', onStart);
sandbox.on('sliceFinish', onFinish);
sandbox.on('terminate', () => {
sandbox.off('start', onStart);
sandbox.off('sliceFinish', onFinish);
});
});
dcpWorker.on('submit', () => {
dcpWorker.on('payment', (payment) => {
dispatchWorkerStats({ type: 'INCREMENT_SLICES' });
});
dcpWorker.on('payment', (receipt) => {
dispatchWorkerStats({
type: 'INCREMENT_CREDITS',
data: receipt.payment,
data: payment,
});
dispatchWorkerState({
type: 'SET_WORKING_SANDBOXES',
data: dcpWorker.workingSandboxes.length,
});
});
dcpWorker.on('fetchStart', () => {
dcpWorker.on('beforeFetch', () => {
dispatchWorkerState({ type: 'FETCHING_TRUE' });
});
dcpWorker.on('fetchEnd', () => {
dcpWorker.on('fetch', (payload) => {
if (payload instanceof Error)
return dispatchWorkerState({ type: 'ERROR', data: payload });
// extra delay for cleaner UI visual updates between quick fetching states

@@ -410,14 +399,10 @@ setTimeout(() => {

});
dcpWorker.on('fetchError', (error) => {
dispatchWorkerState({ type: 'ERROR', data: error });
dcpWorker.on('beforeReturn', () => {
dispatchWorkerState({ type: 'SUBMITTING_TRUE' });
});
dcpWorker.on('submitStart', () => {
dispatchWorkerState({ type: 'SUBMIT_TRUE' });
dcpWorker.on('result', (payload) => {
if (payload instanceof Error)
return dispatchWorkerState({ type: 'ERROR', data: payload });
dispatchWorkerState({ type: 'SUBMITTING_FALSE' });
});
dcpWorker.on('submitEnd', () => {
dispatchWorkerState({ type: 'SUBMIT_FALSE' });
});
dcpWorker.on('submitError', (error) => {
dispatchWorkerState({ type: 'ERROR', data: error });
});
dcpWorker.on('start', () => {

@@ -424,0 +409,0 @@ dispatchWorkerState({ type: 'WORKING_TRUE' });

{
"name": "use-dcp-worker",
"version": "1.0.2",
"version": "1.0.3",
"description": "Embed the DCP Worker in a React app",

@@ -5,0 +5,0 @@ "main": "lib/useDCPWorker.js",

@@ -93,3 +93,3 @@ # use-dcp-worker

- `credits: BigNumber`: Total credits earned.
- `computeTime: number`: Total time computed (ms).
- `computeTime: number`: Total time computed in seconds.
- `workerOptionsState: object`: Refer to `workerOptions` in Parameters. This is to be treated as a read-only object, mutating it will not update worker options.

@@ -96,0 +96,0 @@ - `sandboxes: object`: List of Sandbox objects of sandboxes currently working. Sandbox objects consist of the properties: `id`, `isWorking`, `public`, `sliceStartTime`, and `progress`.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc