Skip to content

Commit

Permalink
Async calls - still in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
jazz-soft committed Sep 11, 2019
1 parent c76ad17 commit 9ffb355
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ module.exports = {
"overrides": [
{
"files": ["test/*"],
"parserOptions": {
"ecmaVersion": 2017
},
"globals": {
"describe": "readonly",
"it": "readonly"
Expand Down
4 changes: 3 additions & 1 deletion javascript/JZZ.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
this._orig._hope = false;
x[0].apply(this, x[1]);
}
else if (this._orig._hope && x[0] == _then) {
x[0].apply(this, x[1]);
}
else {
this._queue = [];
this._orig._hope = false;
}
}
Expand Down
72 changes: 69 additions & 3 deletions test/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,55 @@
var JZZ = require('..');

describe('async calls', function() {
var broke = 'We broke it!';
var notexisting = 'Not existing port';
var notfound = 'Port "Not existing port" not found';

it('await JZZ()', async function() {
var jzz = await JZZ();
await JZZ();
});

it('await JZZ() / throw', async function() {
var msg;
try {
await JZZ().and(function() { this._break(broke); });
}
catch (err) {
msg = err.message;
JZZ()._repair();
}
assert.equal(msg, broke);
});

it('await JZZ().then(...)', async function() {
await JZZ().then(function() {});
await JZZ().then(undefined, function() {});
});

it('await JZZ().then(...) / throw', async function() {
var msg;
try {
await JZZ().and(function() { this._break(broke); }).then(function() {});
}
catch (err) {
msg = err.message;
}
assert.equal(msg, broke);
msg = undefined;
try {
await JZZ().then(undefined, function() {});
}
catch (err) {
msg = err.message;
}
assert.equal(msg, broke);
JZZ()._repair();
});

it('await JZZ().wait(...)', async function() {
await JZZ().wait(1);
});

it('await JZZ().openMidiIn(...)', async function() {
var name = 'Widget MIDI-In';
var widget = {
Expand All @@ -21,8 +61,21 @@ describe('async calls', function() {
}
};
JZZ.lib.registerMidiIn(name, widget);
var port = await JZZ().openMidiIn(name);
await JZZ().openMidiIn(name);
});

it('await JZZ().openMidiIn(...) / throw', async function() {
var msg;
try {
var jzz = await JZZ();
await jzz.openMidiIn(notexisting);
}
catch (err) {
msg = err.message;
}
assert.equal(msg, notfound);
});

it('await JZZ().openMidiOut(...)', async function() {
var name = 'Widget MIDI-Out';
var widget = {
Expand All @@ -33,6 +86,19 @@ describe('async calls', function() {
}
};
JZZ.lib.registerMidiOut(name, widget);
var port = await JZZ().openMidiOut(name);
await JZZ().openMidiOut(name);
});

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

});

0 comments on commit 9ffb355

Please sign in to comment.