A RxJS creation operator based on node-cron, because of that, it is limited to execution in Node only.
Last active
June 5, 2020 10:30
-
-
Save RecuencoJones/a9fbe582548a921ff3a253ad706aaa81 to your computer and use it in GitHub Desktop.
Cron creation operator for RxJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Observable } from 'rxjs' | |
export declare function cron(expr: string): Observable<number> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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