Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add methods to wait for flushing #7

Merged
merged 6 commits into from May 9, 2019

Conversation

Projects
None yet
2 participants
@Raynos
Copy link
Owner

commented May 9, 2019

This allows for better functionality around waiting for SQS
server to do things.

Now we can wait for messages to be received and wait for messages
to have been flushed (aka deleted)

@juliangruber
Copy link
Collaborator

left a comment

this still needs documentation

@@ -9,24 +9,19 @@ class SimplyImitatedSQSHttpServer {
this.server = null
this.hostPort = null
this.waiters = []
this.pendingItems = 0
this.sendItems = 0

This comment has been minimized.

Copy link
@juliangruber

juliangruber May 9, 2019

Collaborator
Suggested change
this.sendItems = 0
this.sentItems = 0

It looks like this would be past tense

This comment has been minimized.

Copy link
@Raynos

Raynos May 9, 2019

Author Owner

willfix.

return process.nextTick(cb)
}

this.waiters.push({ type: 'pending', count: 0, cb: cb })

This comment has been minimized.

Copy link
@juliangruber

juliangruber May 9, 2019

Collaborator

What about instead of manually tracking the subscribers, we inherit from EventEmitter and reuse that logic?

This comment has been minimized.

Copy link
@Raynos

Raynos May 9, 2019

Author Owner

because of managing the count logic using the event emitter doesn't match cleanly.

This comment has been minimized.

This comment has been minimized.

Copy link
@juliangruber

juliangruber May 9, 2019

Collaborator

so to get the count of waiters with type send, you'd do this.listenerCound('send')

This comment has been minimized.

Copy link
@Raynos

Raynos May 9, 2019

Author Owner

count is how many messages to wait for; not related to how many waiters or listeners there are.

This comment has been minimized.

Copy link
@juliangruber

juliangruber May 9, 2019

Collaborator

oooh gotcha!

This comment has been minimized.

Copy link
@juliangruber

juliangruber May 9, 2019

Collaborator

Would still be possible with event emitters but not really an improvement any more:

const onSend = () => cb()
onSend.count = count
this.on('send', onSend)

// after send
const listeners = this.listeners('send')
for (const listener of listeners) {
  listener.count--
}
README.md Outdated
- `opts.port` ; defaults to 0
- `opts.host` ; defaults to `localhost`

Starts the server. cb get's called once listening on a port.

This comment has been minimized.

Copy link
@juliangruber

juliangruber May 9, 2019

Collaborator
Suggested change
Starts the server. cb get's called once listening on a port.
Starts the server. `cb` get's called once listening on a port.
README.md Outdated

### `server.getQueue()`

Returns the current array of items queued in SQS

This comment has been minimized.

Copy link
@juliangruber

juliangruber May 9, 2019

Collaborator

Of what shape are items?

README.md Outdated

### `server.waitForMessages(count, listener)`

Get notified once N messages have been send to this fake SQS

This comment has been minimized.

Copy link
@juliangruber

juliangruber May 9, 2019

Collaborator

listener is a callback, and not an eventemitter listener that can be called multiple times, right?

This comment has been minimized.

Copy link
@Raynos

Raynos May 9, 2019

Author Owner

it's not a cb because there's never an error. It's a listener that gets called once.

Show resolved Hide resolved README.md
Show resolved Hide resolved README.md Outdated
Update README.md
Co-Authored-By: Julian Gruber <julian@juliangruber.com>

@Raynos Raynos merged commit 9306f38 into master May 9, 2019

@Raynos Raynos deleted the wait-for-flush branch May 9, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.