2.0.0 • Published 5 months ago

@differential-dev/sdk v2.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

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

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

  2. 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).

2.0.0

5 months ago

1.1.1

5 months ago

1.0.2

5 months ago

1.0.0

5 months ago

0.0.42

5 months ago

0.0.41

5 months ago

0.0.40

5 months ago

0.0.39

5 months ago

0.0.38

5 months ago

0.0.37

5 months ago

0.0.36

5 months ago

0.0.35

5 months ago

0.0.34

5 months ago

0.0.33

6 months ago

0.0.32

6 months ago

0.0.31

6 months ago

0.0.30

6 months ago

0.0.27

6 months ago

0.0.26

6 months ago

0.0.25

6 months ago

0.0.24

6 months ago

0.0.23

6 months ago

0.0.22

6 months ago

0.0.21

6 months ago

0.0.20

6 months ago

0.0.19

7 months ago

0.0.18

7 months ago

0.0.16

8 months ago

0.0.15

8 months ago

0.0.14

8 months ago

0.0.13

8 months ago

0.0.12

8 months ago

0.0.11

8 months ago

0.0.9

8 months ago

0.0.8

9 months ago

0.0.7

9 months ago

0.0.6

9 months ago

0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago