Skip to content

Commit

Permalink
Merge pull request #1356 from Agoric/mfig/break-notifier-cycle
Browse files Browse the repository at this point in the history
refactor: break the cycle between notifier and adaptor
  • Loading branch information
michaelfig authored Aug 1, 2020
2 parents 2c7ba13 + e8a2132 commit 8d02c0b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/notifier/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@agoric/notifier",
"version": "0.1.3",
"description": "Notifier allows services to update clients about state changes using a stream of promises",
"main": "src/notifier.js",
"main": "src/index.js",
"engines": {
"node": ">=11.0"
},
Expand Down
15 changes: 0 additions & 15 deletions packages/notifier/src/asyncIterableAdaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
/// <reference types="ses"/>

import { E } from '@agoric/eventual-send';
// eslint-disable-next-line import/no-cycle
import { makeNotifierKit } from './notifier';

import './types';

Expand Down Expand Up @@ -129,19 +127,6 @@ export const updateFromIterable = (updater, asyncIterable) => {
});
};

/**
* Adaptor from async iterable to notifier.
*
* @template T
* @param {AsyncIterable<T>} asyncIterable
* @returns {Notifier<T>}
*/
export const makeNotifierFromAsyncIterable = asyncIterable => {
const { notifier, updater } = makeNotifierKit();
updateFromIterable(updater, asyncIterable);
return notifier;
};

/**
* As updates come in from the possibly remote `notifierP`, update
* the local `updater`. Since the updates come from a notifier, they
Expand Down
2 changes: 2 additions & 0 deletions packages/notifier/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './notifier';
export * from './asyncIterableAdaptor';
19 changes: 17 additions & 2 deletions packages/notifier/src/notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

import { producePromise } from '@agoric/produce-promise';
import { assert } from '@agoric/assert';
// eslint-disable-next-line import/no-cycle
import { makeAsyncIterableFromNotifier } from './asyncIterableAdaptor';
import {
makeAsyncIterableFromNotifier,
updateFromIterable,
} from './asyncIterableAdaptor';

import './types';

Expand Down Expand Up @@ -118,3 +120,16 @@ export const makeNotifierKit = (...args) => {
// is tightly held
return harden({ notifier, updater });
};

/**
* Adaptor from async iterable to notifier.
*
* @template T
* @param {AsyncIterable<T>} asyncIterable
* @returns {Notifier<T>}
*/
export const makeNotifierFromAsyncIterable = asyncIterable => {
const { notifier, updater } = makeNotifierKit();
updateFromIterable(updater, asyncIterable);
return notifier;
};
2 changes: 1 addition & 1 deletion packages/notifier/test/test-notifier-adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
makeNotifierFromAsyncIterable,
updateFromIterable,
updateFromNotifier,
} from '../src/asyncIterableAdaptor';
} from '../src/index';

const obj = harden({});
const unresP = new Promise(_ => {});
Expand Down
2 changes: 1 addition & 1 deletion packages/notifier/test/test-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import '@agoric/install-ses';

import test from 'tape-promise/tape';
import { makeNotifierKit } from '../src/notifier';
import { makeNotifierKit } from '../src/index';

import '../src/types';

Expand Down

0 comments on commit 8d02c0b

Please sign in to comment.