.load method returns a Promise

This commit is contained in:
Yotam Mann 2016-11-06 19:16:31 -05:00
parent 45eba82840
commit 3ca0eadafd
2 changed files with 12 additions and 3 deletions

View file

@ -129,11 +129,10 @@ define(["Tone/core/Tone", "Tone/core/Buffer", "Tone/source/Source"], function(To
* browser.
* @param {function=} callback The function to invoke once
* the sample is loaded.
* @returns {Tone.Player} this
* @returns {Promise}
*/
Tone.Player.prototype.load = function(url, callback){
this._buffer.load(url, this._onload.bind(this, callback));
return this;
return this._buffer.load(url, this._onload.bind(this, callback));
};
/**
@ -141,6 +140,7 @@ define(["Tone/core/Tone", "Tone/core/Buffer", "Tone/source/Source"], function(To
* @private
*/
Tone.Player.prototype._onload = function(callback){
callback = this.defaultArg(callback, Tone.noOp);
callback(this);
if (this.autostart){
this.start();

View file

@ -54,6 +54,15 @@ define(["helper/Basic", "Tone/source/Player", "helper/Offline",
});
});
it("returns a promise", function(done){
var player = new Player();
var promise = player.load("./audio/sine.wav");
expect(promise).to.be.instanceof(Promise);
promise.then(function(){
done();
});
});
it("can be created with an options object", function(){
var player = new Player({
"url" : "./audio/sine.wav",