Skip to content

Instantly share code, notes, and snippets.

@RecuencoJones
Last active June 5, 2020 10:30
Show Gist options
  • Save RecuencoJones/a9fbe582548a921ff3a253ad706aaa81 to your computer and use it in GitHub Desktop.
Save RecuencoJones/a9fbe582548a921ff3a253ad706aaa81 to your computer and use it in GitHub Desktop.
Cron creation operator for RxJS
import { Observable } from 'rxjs'
export declare function cron(expr: string): Observable<number>
const { Observable } = require('rxjs')
const { schedule } = require('node-cron')
function cron(expr) {
let counter = 0
return new Observable((subscriber) => {
const task = schedule(expr, () => {
subscriber.next(counter++)
})
task.start()
return () => task.destroy()
})
}
module.exports = { cron }
{
"name": "rxjs-cron",
"version": "0.1.0",
"main": "index.js",
"types": "index.d.ts",
"peerDependencies": {
"rxjs": ">= 6"
},
"dependencies": {
"node-cron": "^2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment