Open mxkrn opened 4 years ago
var fsPromises = require('fs').promises;
fsPromises.readFile(cache_file).then(function(data) {
return new Promise(function(resolve, reject) {
offlineContext.decodeAudioData(data, function(dataBuffer) {
return resolve(dataBuffer);
}, function(err) {
reject(err);
});
});
}).then(function(bufferResult) {
//do something
});
var fsPromises = require('fs').promises; fsPromises.readFile(cache_file).then(function(data) { return new Promise(function(resolve, reject) { offlineContext.decodeAudioData(data, function(dataBuffer) { return resolve(dataBuffer); }, function(err) { reject(err); }); }); }).then(function(bufferResult) { //do something });
offlineaudiocontext is not supported in this project isn't it?
So I found some very strange error behaviour when using an async version of AudioContext.decodeAudioData. When using the function as designed with a regular callback, I can access and log the decoded data just fine, however I need to return this data so I want to store in a variable so I can use await. So I turned encapsulating the function in a Promise using promisify, here's my code:
When I call this, the error is thrown, but the error isn't actually an error, the entire decoded data is logged to the console as the error! I saved both the console.log output and the error log in text files and confirm that both are identical. After that, I also tried bluebird with the same result.
All-in-all this seems incredibly strange, anyone got any insight into what's happening here?