npm.io
1.0.1 • Published 5 years ago

ts-schedule

Licence
ISC
Version
1.0.1
Deps
1
Size
7 kB
Vulns
0
Weekly
0

ts-schedule

Statements Branches Functions Lines
Statements Branches Functions Lines

Allows scheduling functionality in TypeScript using decorators.

Prerequisites

npm install ts-schedule

To use decorators in TypeScript, you will need to add the following to your tsconfig.json:

{
  "compilerOptions": {
    "experimentalDecorators": true
  }
}

Usage

@enableScheduling()
class Foo {
  @scheduled(1000) // bar1 will run every 1000ms
  bar1() {
    console.log('bar1');
  }

  @scheduled(1000, 5000) // bar2 will run every 1000ms after an intial 5000ms delay
  bar2() {
    console.log('bar2');
  }
}

new Foo();
Output
bar1
bar1
bar1
bar1
bar2
bar1
bar2
bar1

Keywords