mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
// Type definitions for RxJS bindings for Node
|
|
// Project: https://github.com/Reactive-Extensions/rx-node
|
|
// Definitions by: Andre Luiz dos Santos <https://github.com/andre-luiz-dos-santos/>
|
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
|
|
{
|
|
var source = Rx.Observable.return(42);
|
|
var emitter = RxNode.toEventEmitter(source, 'data');
|
|
|
|
emitter.on('data', function(data: number) {
|
|
console.log('Data: ' + data);
|
|
});
|
|
|
|
emitter.on('end', function() {
|
|
console.log('End');
|
|
});
|
|
|
|
// Ensure to call publish to fire events from the observable
|
|
emitter.publish();
|
|
}
|
|
{
|
|
var subscription = RxNode.fromStream<string>(process.stdin, 'end')
|
|
.subscribe(function(x) { console.log(x); });
|
|
}
|
|
{
|
|
var subscription = RxNode.fromReadableStream(process.stdin)
|
|
.subscribe(function(x) { console.log(x); });
|
|
}
|
|
{
|
|
var readline = require('readline');
|
|
var fs = require('fs');
|
|
|
|
var rl = readline.createInterface({
|
|
input: fs.createReadStream('sample.txt')
|
|
});
|
|
|
|
var subscription = RxNode.fromReadLineStream(rl)
|
|
.subscribe(function(x) { console.log(x); });
|
|
}
|
|
{
|
|
var subscription = RxNode.fromWritableStream(process.stdout)
|
|
.subscribe(function(x) { console.log(x); });
|
|
}
|
|
{
|
|
var source = Rx.Observable.range(0, 5);
|
|
var subscription = RxNode.writeToStream(source, process.stdout, 'utf8');
|
|
}
|