mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
* Add type definitions for async-stream-emitter, consumable-stream, writable-consumable-stream, stream-demux, ag-channel, ag-simple-broker, ncom, async-iterable-stream * Upgrade sc-broker to 8.0 * Upgrade socketcluster-client to 15.1 * Rename definition files to match module file names The files in the module were renamed. * Move socketcluster-server to v14 folder In preparation for socketcluster-server v15, since the old version is still used by other type packages. * Update scc-broker-client to 7.0 * Add current socketcluster-server type definitions Current version is v15.0 * Move sc-broker-cluster to v6 folder In preparation for sc-broker-cluster v9, since the old version is still used by other type packages. * Add current sc-broker-cluster type definitions Current version is v9.0 * Move sc-channel to v1 folder In preparation for sc-channel v2, since the old version is still used by other type packages. * Add current sc-channel type definitions Current version is v2.0 * Include the relevant sc-broker-cluster type-definitions directly in sc-channel It can be run using older and newer version of sc-broker-cluster, which have differently versioned dependencies. * Move sc-channel tests to sc-broker-cluster In the tests we use sc-broker-cluster. If the tests are in sc-channel, they drag in all dependencies for sc-broker-cluster, including esnext.asynciterable, which we don't want. * Simplify sc-errors tests In the tests we used socketcluster-server. That dragged in all of its dependencies, including esnext.asynciterable, which we don't want. * Move sc-channel to v1 folder In preparation for sc-channel v2, since the old version is still used by other type packages.
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import WritableConsumableStream = require('writable-consumable-stream');
|
|
|
|
const consumableStream = new WritableConsumableStream<string>();
|
|
|
|
async function consumeAsyncIterable1(asyncIterable: WritableConsumableStream<string>) {
|
|
// Consume iterable data asynchronously.
|
|
// tslint:disable-next-line: await-promise Bug in tslint: https://github.com/palantir/tslint/issues/3997
|
|
for await (const packet of asyncIterable) {
|
|
console.log('Packet:', packet);
|
|
}
|
|
}
|
|
consumeAsyncIterable1(consumableStream);
|
|
|
|
setInterval(() => {
|
|
// Write data to the stream asynchronously,
|
|
consumableStream.write(`Timestamp: ${Date.now()}`);
|
|
}, 100);
|
|
|
|
async function consumeAsyncIterable2(asyncIterable: WritableConsumableStream<string>) {
|
|
// Consume iterable data asynchronously.
|
|
// Works in older environments.
|
|
const asyncIterator = asyncIterable.createConsumer();
|
|
while (true) {
|
|
const packet = await asyncIterator.next();
|
|
if (packet.done) break;
|
|
console.log('Packet:', packet.value);
|
|
}
|
|
}
|
|
consumeAsyncIterable2(consumableStream);
|
|
|
|
setInterval(() => {
|
|
// Write data to the stream asynchronously,
|
|
consumableStream.write(`Timestamp: ${Date.now()}`);
|
|
}, 100);
|
|
|
|
setInterval(() => {
|
|
// Write data to the stream asynchronously,
|
|
consumableStream.write(`Timestamp: ${Date.now()}`);
|
|
}, 100);
|
|
|
|
(async () => {
|
|
const data = await consumableStream.once();
|
|
console.log(data);
|
|
})();
|
|
|
|
setInterval(() => {
|
|
// Write data to the stream asynchronously,
|
|
consumableStream.write(`Timestamp: ${Date.now()}`);
|
|
}, 100);
|