Socket
Book a DemoInstallSign in
Socket

@differential-dev/sdk

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@differential-dev/sdk

Javascript SDK for differential.dev

2.0.0
unpublished
latest
npmnpm
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Differential SDK

This is the official Differential SDK for JavaScript.

Differential allows two or more compute instances to communicate with each other just by calling functions.

This allows you to easily distribute work across multiple machines, and even across multiple processes on the same machine, without having to worry about the underlying communication logic like building a message queue or setting up a REST API.

Installation

npm install @differential-dev/sdk

Quick Start

import process from 'process';
import { Differential } from "@differential-dev/sdk";

export const d = Differential({
  apiSecret: "sk_excellent_beans_1234",
});

// initialize the communication. this starts listening for queued function calls
d.listen({
  asPool: "worker", // this listening process will run as the "worker" worker pool
});

// define any function and wrap it with d.fn to run it in a distributed manner
const helloWorld = d.fn((pid) => {
  return `Hello from pid ${process.pid}!`;
}, {
  pool: "worker", // this function will only run on workers
})

// call the function as if it were a normal function in the same process
// the SDK will handle the distribution logic
helloWorld(process.pid).then((result) => {
  console.log(result);
});

// call d.quit() on process exit to gracefully shut down the SDK
process.on("exit", () => {
  d.quit();
});

Examples

  • Counter / Greeter shows how two independent processes can communicate with each other.

  • API / Worker shows how to create a simple API that offloads work to a worker process that gets executed in the background (set and forget).

FAQs

Package last updated on 09 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.