-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
42 lines (37 loc) · 1016 Bytes
/
index.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
/*!
* letta-value <https://github.com/hybridables/letta-value>
*
* Copyright (c) 2015 Charlike Mike Reagent <@tunnckoCore> (http://www.tunnckocore.tk)
* Released under the MIT license.
*/
'use strict'
var utils = require('./utils')
module.exports = function lettaValue (val) {
if (utils.isNodeStream(val) || utils.isChildProcess(val)) {
return utils.letta(utils.onStreamEnd, utils.streamExhaust(val))
}
if (val && typeof val.subscribe === 'function') {
if (val.value) {
return utils.letta(function () {
return val.value
})
}
return utils.letta(subscribe, val)
}
if (utils.isTypeofError(val)) {
return utils.letta(function () {
throw val
})
}
return utils.letta(function () {
return val
})
}
/**
* Callback-style wrapper for `rx.subscribe`
*/
function subscribe (val, callback) {
val.subscribe(function noop () {}, callback, function onComplete () {
callback.apply(this, [null].concat(utils.sliced(arguments)))
}.bind(this))
}