UNPKG

1.53 kBTypeScriptView Raw
1import { EventStream } from "./observable";
2/**
3 Creates an EventStream from a function that
4 accepts a callback. The function is supposed to call its callback just
5 once. For example:
6
7 ```js
8 Bacon.fromCallback(callback => callback("bacon"))
9 ```
10
11 This would create a stream that outputs a single value "Bacon!" and ends
12 after that. The use of setTimeout causes the value to be delayed by 1
13 second.
14
15 You can also give any number of arguments to [`fromCallback`](#bacon-fromcallback), which will be
16 passed to the function. These arguments can be simple variables, Bacon
17 EventStreams or Properties. For example the following will output "Bacon rules":
18
19 ```js
20 bacon = Bacon.constant('bacon')
21 Bacon.fromCallback(function(a, b, callback) {
22 callback(a + ' ' + b);
23}, bacon, 'rules').log();
24 ```
25
26 * @param f
27 * @param args
28 * @returns {EventStream<V>}
29 */
30export declare function fromCallback<V>(f: Function, ...args: any[]): EventStream<V>;
31/**
32Behaves the same way as `Bacon.fromCallback`,
33except that it expects the callback to be called in the Node.js convention:
34`callback(error, data)`, where error is null if everything is fine. For example:
35
36```js
37var Bacon = require('baconjs').Bacon,
38fs = require('fs');
39var read = Bacon.fromNodeCallback(fs.readFile, 'input.txt');
40read.onError(function(error) { console.log("Reading failed: " + error); });
41read.onValue(function(value) { console.log("Read contents: " + value); });
42```
43
44 */
45export declare function fromNodeCallback<V>(f: Function, ...args: any[]): EventStream<V>;