0.5.0 • Published 1 year ago

@defer.run/client v0.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@defer.run/client

defer is your favorite background tasks handler to offload your JavaScript API.

Install

yarn add @defer.run/client

# or

npm i @defer.run/client

Configuration

Make sure to define the DEFER_TOKEN environment variable in production/staging environments.

Usage

1. Define your background function

A background function should be a unique default export of a file placed in background-functions/ folder.

import { defer } from "@defer.run/client";

function importContacts(intercomId: string) {
  // import contacts from Hubspot and insert them in the database
}

export default defer(importContacts)

2. Call your background function

For a seamless integration with your project, we recommend to install our @defer.run/babel babel plugin. Our babel plugin will replace all usage of defer functions to client pushes:

import type { NextApiRequest, NextApiResponse } from "next";
import sentToIntercom from "../../background-functions/importContacts";

export default function handler(req: NextApiRequest, res: NextApiResponse) {
  // will be executed in the background
  await importContacts(currentUser.intercomId);

  res.status(200).json({ name: "John Doe" });
}
0.3.0

1 year ago

0.5.0

1 year ago

0.2.3

1 year ago

0.4.0

1 year ago

0.2.2

1 year ago

0.0.15

2 years ago

0.0.16

1 year ago

0.1.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago