Skip to content

Commit

Permalink
Async calls complete
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Sep 13, 2019
1 parent fead25a commit 7e7dce9
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 3 deletions.
9 changes: 6 additions & 3 deletions javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
this._push(_wait, [ret, delay]);
return ret._thenable();
};
function _kick(obj) { obj._resume(); }
function _kick(obj) { if (this._bad) obj._break(this._err()); obj._resume(); }
function _rechain(self, obj, name) {
self[name] = function() {
var arg = arguments;
Expand Down Expand Up @@ -110,8 +110,11 @@
_R.prototype.name = function() { return this.info().name; };

function _close(obj) {
this._break('closed');
obj._resume();
if (this._bad) obj._crash(this._err());
else {
this._break('Closed');
obj._resume();
}
}
_R.prototype.close = function() {
var ret = new _R();
Expand Down
83 changes: 83 additions & 0 deletions test/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,87 @@ describe('async calls', function() {
assert.equal(msg, notfound);
});

it('await JZZ().openMidiOut().ch()', async function() {
JZZ.lib.registerMidiOut(midi_out_name, midi_out_impl);
await JZZ().openMidiOut(midi_out_name).wait(1).ch(0);
});

it('await JZZ().openMidiOut().ch() / throw 1', async function() {
var msg;
try {
await JZZ().openMidiOut(notexisting).wait(1).ch(0);
}
catch (err) {
msg = err.message;
}
assert.equal(msg, notfound);
});


it('await JZZ().openMidiOut().ch() / throw 2', async function() {
var msg;
try {
await JZZ().openMidiOut(notexisting).wait(1).ch(0).noteOn('C5');
}
catch (err) {
msg = err.message;
}
assert.equal(msg, notfound);
});

it('await JZZ().openMidiOut().mpe()', async function() {
JZZ.lib.registerMidiOut(midi_out_name, midi_out_impl);
await JZZ().openMidiOut(midi_out_name).wait(1).mpe(0, 5);
});

it('await JZZ().openMidiOut().mpe() / throw 1', async function() {
var msg;
try {
await JZZ().openMidiOut(notexisting).wait(1).mpe(0, 5);
}
catch (err) {
msg = err.message;
}
assert.equal(msg, notfound);
});

it('await JZZ().openMidiOut().mpe() / throw 2', async function() {
var msg;
try {
await JZZ().openMidiOut(notexisting).wait(1).mpe(0, 5).wait(1).noteOn('C5');
}
catch (err) {
msg = err.message;
}
assert.equal(msg, notfound);
});

it('await JZZ().openMidiOut().close()', async function() {
JZZ.lib.registerMidiOut(midi_out_name, midi_out_impl);
await JZZ().openMidiOut(midi_out_name).wait(1).close().wait(1);
});

it('await JZZ().openMidiOut().close() / throw 1', async function() {
JZZ.lib.registerMidiOut(midi_out_name, midi_out_impl);
var msg;
try {
await JZZ().openMidiOut(midi_out_name).wait(1).close().wait(1).noteOn(0, 'C5', 127);
}
catch (err) {
msg = err.message;
}
assert.notEqual(msg, undefined);
});

it('await JZZ().openMidiOut().close() / throw 2', async function() {
var msg;
try {
await JZZ().openMidiOut(notexisting).wait(1).close();
}
catch (err) {
msg = err.message;
}
assert.equal(msg, notfound);
});

});

0 comments on commit 7e7dce9

Please sign in to comment.