checking for 'then' instead of 'instanceof Promise'

This commit is contained in:
Yotam Mann 2018-05-19 13:39:39 -04:00
parent abcd3b2696
commit bc7269e740
4 changed files with 25 additions and 26 deletions

View file

@ -66,7 +66,7 @@ define(["Tone/core/Tone", "Tone/core/Transport", "Tone/core/Buffer", "Tone/core/
var context = renderRet.context;
var ret;
if (response instanceof Promise){
if (response && Tone.isFunction(response.then)){
//wait for the promise to resolve
ret = response.then(function(){
//then render the audio

View file

@ -40,7 +40,7 @@ define(["Tone/core/Tone", "Tone/shim/OfflineAudioContext"], function(Tone){
var audioData = new Uint32Array([1179011410, 48, 1163280727, 544501094, 16, 131073, 44100, 176400, 1048580, 1635017060, 8, 0, 0, 0, 0]).buffer;
try {
var ret = offlineContext.decodeAudioData(audioData);
if (ret instanceof Promise){
if (ret && Tone.isFunction(ret.then)){
decodeAudioDataPromise = true;
}
} catch (e){

View file

@ -8,7 +8,7 @@ define(["Tone/core/Tone"], function(Tone){
//returns promise?
var context = new OfflineAudioContext(1, 1, 44100);
var ret = context.startRendering();
if (!(ret instanceof Promise)){
if (!(ret && Tone.isFunction(ret.then))){
OfflineAudioContext.prototype._native_startRendering = OfflineAudioContext.prototype.startRendering;
OfflineAudioContext.prototype.startRendering = function(){
return new Promise(function(done){

View file

@ -1,24 +1,23 @@
define(["Tone/core/Tone", "Tone/core/Offline", "helper/BufferTest", "Tone/core/Master"],
function(Tone, Offline, BufferTest, Master) {
define(["Tone/core/Tone", "Tone/core/Offline", "helper/BufferTest", "Tone/core/Master"], function(Tone, Offline, BufferTest, Master){
return function(callback, duration, channels){
duration = duration || 0.1;
channels = channels || 1;
return Offline(function(Transport){
var testFn = callback(Transport);
if (testFn instanceof Promise){
return testFn;
} else if (Tone.isFunction(testFn)){
Transport.context.on("tick", function(){
testFn(Transport.now());
});
}
}, duration).then(function(buffer){
BufferTest(buffer);
if (channels === 1){
buffer.toMono();
}
return buffer;
});
};
});
return function(callback, duration, channels){
duration = duration || 0.1;
channels = channels || 1;
return Offline(function(Transport){
var testFn = callback(Transport);
if (testFn && Tone.isFunction(testFn.then)){
return testFn;
} else if (Tone.isFunction(testFn)){
Transport.context.on("tick", function(){
testFn(Transport.now());
});
}
}, duration).then(function(buffer){
BufferTest(buffer);
if (channels === 1){
buffer.toMono();
}
return buffer;
});
};
});