Last active
June 22, 2017 19:13
-
-
Save boxxa/b88d6670c1a1d34d7d7428a886d88838 to your computer and use it in GitHub Desktop.
Fibers
This file contains hidden or 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
var Fiber = require("fibers"); | |
Fiber(function(){ | |
var dataSet = $proc.data.fetchData(); | |
console.log("Running Calc") | |
var calcResult = $proc.ta.calc(dataSet) | |
console.log("Done with Calc") | |
console.log(calcResult) | |
}).run(); | |
Output: | |
Running Calculations | |
Done with Calculations | |
undefined | |
Done <-the proc.ta.calc gets done here and logs the function is complete | |
proc.data.fetchData = function(){ | |
var res = request('GET', "www.exampe.com/api/data") | |
data = JSON.parse(res.getBody('utf8')) | |
return data | |
} | |
proc.ta.calc = function(series){ | |
talib.execute({ | |
name: "SMA", | |
startIdx: 0, | |
endIdx: series.length - 1, | |
inReal: series, | |
optInTimePeriod: 200 | |
}, function (err, result) { | |
// Show the result array | |
if(!err) | |
{ | |
console.log("Done") | |
return result | |
} else { | |
return new Error(err) | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment