-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.js
47 lines (37 loc) · 1.05 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict'
var utils = require('lazy-cache')(require)
var fn = require
require = utils // eslint-disable-line no-undef, no-native-reassign, no-global-assign
/**
* Lazily required module dependencies
*/
require('is-child-process')
require('is-node-stream')
require('is-promise')
require('is-typeof-error')
require('on-stream-end')
require('stream-exhaust')
require('try-catch-core')
require = fn // eslint-disable-line no-undef, no-native-reassign, no-global-assign
utils.subscribe = function subscribe (val, done) {
function onNext (state) {
onNext.state = state
}
val.subscribe(onNext, done, function observableCallback () {
done(null, onNext.state)
})
}
utils.handleStreams = function handleStreams (val, done) {
var stream = utils.streamExhaust(val)
process.once('newListener', function onNewListener (name) {
this.removeAllListeners(name)
})
process.once('uncaughtException', function onerror (err) {
stream.emit('error', err)
})
utils.onStreamEnd(stream, done)
}
/**
* Expose `utils` modules
*/
module.exports = utils