New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@appliedblockchain/event-recorder

Package Overview
Dependencies
Maintainers
28
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@appliedblockchain/event-recorder - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

26

lib/event-recorder.js

@@ -36,6 +36,7 @@ 'use strict';

includes(name, source, gteIndex = 0) {
// Returns first matching event or null.
first(name, source, gteIndex = 0) {
const records = this.map.get(name);
if ((0, _lodash.isNil)(records)) {
return false;
return null;
}

@@ -45,16 +46,15 @@ for (let i = records.length - 1; i >= gteIndex; i--) {

if (isOk(record.event, source)) {
return true;
return record.event;
}
}
return false;
return null;
}
async eventuallyIncludes(name, source) {
async eventuallyFirst(name, source, gteIndex = 0) {
const timeout = Date.now() + 60 * 1000;
const probeEvery = 0.1 * 1000;
let i = 0;
let result = false;
let i = gteIndex;
let result = null;
while (Date.now() <= timeout) {
if (this.includes(name, source, i)) {
result = true;
if (!(0, _lodash.isNil)(result = this.first(name, source, i))) {
break;

@@ -68,2 +68,10 @@ }

includes(name, source, gteIndex = 0) {
return !(0, _lodash.isNil)(this.first(name, source, gteIndex));
}
async eventuallyIncludes(name, source, gteIndex = 0) {
return !(0, _lodash.isNil)((await this.eventuallyFirst(name, source, gteIndex)));
}
}

@@ -70,0 +78,0 @@ exports.default = EventRecorder;

{
"name": "@appliedblockchain/event-recorder",
"version": "0.1.1",
"version": "0.2.0",
"description": "Event recorder simplifies evented/async tests.",

@@ -5,0 +5,0 @@ "main": "lib/event-recorder.js",

@@ -33,6 +33,7 @@ // @flow

includes(name: string, source: Source, gteIndex: number = 0): boolean {
// Returns first matching event or null.
first(name: string, source: Source, gteIndex: number = 0): any {
const records = this.map.get(name)
if (isNil(records)) {
return false
return null
}

@@ -42,16 +43,15 @@ for (let i = records.length - 1; i >= gteIndex; i--) {

if (isOk(record.event, source)) {
return true
return record.event
}
}
return false
return null
}
async eventuallyIncludes(name: string, source: Source): Promise<boolean> {
async eventuallyFirst(name: string, source: Source, gteIndex: number = 0): Promise<any> {
const timeout = Date.now() + 60 * 1000
const probeEvery = 0.1 * 1000
let i = 0
let result = false
let i = gteIndex
let result = null
while (Date.now() <= timeout) {
if (this.includes(name, source, i)) {
result = true
if (!isNil(result = this.first(name, source, i))) {
break

@@ -65,2 +65,10 @@ }

includes(name: string, source: Source, gteIndex: number = 0): boolean {
return !isNil(this.first(name, source, gteIndex))
}
async eventuallyIncludes(name: string, source: Source, gteIndex: number = 0): Promise<boolean> {
return !isNil(await this.eventuallyFirst(name, source, gteIndex))
}
}

@@ -43,1 +43,9 @@ // @flow

})
test('first + eventually first', async () => {
setTimeout(() => {
recorder.record('foo', { foo: 'xyz', bar: 'xyz' })
}, 2 * 1000)
expect(recorder.first('foo', { foo: 'xyz' })).toBeNull()
expect(await recorder.eventuallyFirst('foo', { foo: 'xyz' })).toEqual({ foo: 'xyz', bar: 'xyz' })
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc