Skip to content

Commit

Permalink
chore: lint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Apr 27, 2021
1 parent 4b08603 commit feff8f6
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 17 deletions.
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -37,7 +37,9 @@
"build": "lerna run build"
},
"dependencies": {
"patch-package": "^6.2.2"
"@agoric/eslint-plugin": "^0.2.3",
"patch-package": "^6.2.2",
"prettier": "^1.19.1"
},
"ava": {
"files": [
Expand Down
6 changes: 3 additions & 3 deletions packages/stdlib/src/async.js
Expand Up @@ -3,7 +3,7 @@ import { makePromise } from './makers';

/**
* Resolve promise when await asyncPredThunk() returns falsy.
*
*
* @template T
* @param {() => (T | Promise<T>)} asyncPredThunk Return truthy or a
* Promise<truthy> to keep looping.
Expand Down Expand Up @@ -31,7 +31,7 @@ export { asyncWhile };
/**
* Return an async iterable that produces values with asyncValThunk. Finish
* with the last value when it is falsy.
*
*
* @template T
* @param {() => T | Promise<T>} asyncValThunk thunk to call to create the next
* value. When falsy, finish the iterator.
Expand All @@ -53,4 +53,4 @@ const asyncAllTruthies = asyncValThunk => {
});
};
harden(asyncAllTruthies);
export { asyncAllTruthies };
export { asyncAllTruthies };
8 changes: 7 additions & 1 deletion packages/stdlib/src/main.js
@@ -1,3 +1,9 @@
// This module should be overridden by Jessie interpreters.
export { makePromise, makeMap, makeSet, makeWeakMap, makeWeakSet } from './makers.js';
export {
makePromise,
makeMap,
makeSet,
makeWeakMap,
makeWeakSet,
} from './makers.js';
export { asyncWhile, asyncAllTruthies } from './async.js';
12 changes: 7 additions & 5 deletions packages/stdlib/src/makers.js
Expand Up @@ -2,8 +2,10 @@
/// <reference types="ses" />

// TODO: Typing these would be laudable, but harder than it looks.
export const makePromise = harden((executor) => harden(new Promise(executor)));
export const makeMap = harden((entriesOrIterable) => harden(new Map(entriesOrIterable)));
export const makeSet = harden((values) => harden(new Set(values)));
export const makeWeakMap = harden((entries) => harden(new WeakMap(entries)));
export const makeWeakSet = harden((values) => harden(new WeakSet(values)));
export const makePromise = harden(executor => harden(new Promise(executor)));
export const makeMap = harden(entriesOrIterable =>
harden(new Map(entriesOrIterable)),
);
export const makeSet = harden(values => harden(new Set(values)));
export const makeWeakMap = harden(entries => harden(new WeakMap(entries)));
export const makeWeakSet = harden(values => harden(new WeakSet(values)));
16 changes: 12 additions & 4 deletions packages/stdlib/test/test-async.js
Expand Up @@ -2,7 +2,7 @@
import { test } from '@agoric/swingset-vat/tools/prepare-test-env-ava';
import { asyncAllTruthies, asyncWhile } from '../src/async';

test('asyncAllTruthies', async t => {
test('asyncAllTruthies - for-await-of', async t => {
const results = [];
let state = 4;
const thunk = async () => {
Expand All @@ -14,12 +14,20 @@ test('asyncAllTruthies', async t => {
results.push(el);
}
t.deepEqual(results, [4, 3, 2, 1]);
});

test('asyncAllTruthies - manual iteration', async t => {
let state = 4;
const thunk = async () => {
const cur = await Promise.resolve(state);
state -= 1;
return cur;
};

state = 4;
const results2 = [];
const ai = asyncAllTruthies(thunk)[Symbol.asyncIterator]();

for (let count = 4; count > 0; count -= 1) {
// eslint-disable-next-line no-await-in-loop
const r = await ai.next();
t.is(r.value, count);
t.is(r.done, false);
Expand All @@ -35,7 +43,7 @@ test('asyncWhile', async t => {
const cur = await Promise.resolve(state);
state -= 1;
return cur;
}
};
const last = await asyncWhile(thunk);
t.is(last, 0);
t.is(state, -1);
Expand Down
15 changes: 12 additions & 3 deletions packages/stdlib/test/test-makers.js
Expand Up @@ -10,12 +10,21 @@ test('makePromise', async t => {
});

test('makeMap', async t => {
const init = [['abc', 123], ['def', 456]];
const init = [
['abc', 123],
['def', 456],
];
const map = makeMap(init);

t.deepEqual([...map.entries()], init);
t.deepEqual([...map.keys()], init.map(([k]) => k));
t.deepEqual([...map.values()], init.map(([_k, v]) => v));
t.deepEqual(
[...map.keys()],
init.map(([k]) => k),
);
t.deepEqual(
[...map.values()],
init.map(([_k, v]) => v),
);

const bar = {};
t.is(map.get('abc'), 123);
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Expand Up @@ -72,6 +72,13 @@
resolved "https://registry.yarnpkg.com/@agoric/eslint-config/-/eslint-config-0.2.1.tgz#e18d548fbf2d41ed6dce0303402ffed82b4973ba"
integrity sha512-0VJdY28OA1q57QnZHPUlmKO3aMe0MAIoYimwvpr2W5PViq5eZQb9CclpMD6Bliosn54Js0S5CCA1V8VBJfIrPA==

"@agoric/eslint-plugin@^0.2.3":
version "0.2.3"
resolved "https://registry.yarnpkg.com/@agoric/eslint-plugin/-/eslint-plugin-0.2.3.tgz#29734731b2bcfcb4bb259f531fcf0125772c3bfd"
integrity sha512-m0GcNDf4L8WCQMbDrdq7dv4RVYly7YvDm6Xs2C3/Zq2FQGli9TjuR38SA41HXpf1O9Vaz20YpchuLjx/CP8uKQ==
dependencies:
requireindex "~1.1.0"

"@agoric/eventual-send@^0.13.11":
version "0.13.11"
resolved "https://registry.yarnpkg.com/@agoric/eventual-send/-/eventual-send-0.13.11.tgz#9158a0b36dad625527c9ae28e5210b5ad520a53f"
Expand Down

0 comments on commit feff8f6

Please sign in to comment.