This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
go build for linux: | |
env GOOS=linux go build -o /tmp/server server.go | |
run with docker: | |
docker run -it --rm --name test -v /tmp/server:/server -p 3000:80 -p 3001:6060 alpine /server | |
run pprof debugger: | |
go get github.com/google/pprof | |
pprof --seconds 30 -http=:4444 /tmp/server http://localhost:3001/debug/pprof/profile |
I hereby claim:
- I am automaticalldramatic on github.
- I am reeseone (https://keybase.io/reeseone) on keybase.
- I have a public key ASDcrqAF-d20V6sFhvrFoQqWZH8QdE7o_lDOm2EDLFt7awo
To claim this, I am signing this object:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface ObservablePaginatedResult { | |
cards: Observable<Array<SomeCards>>; | |
stop: () => void; | |
} | |
// returns an observable to subscribe to for changes and a method to stop listening to the snapshot | |
public SyncCards(pageSize: number = this.DefaultPageSize): <ObservablePaginatedResult> { | |
// an internal subject to handle streaming until the connection is closed. The buffer size of 1 fits my scenario and is up to the readers discretion | |
const cards$: ReplaySubject<Array<SomeCards>> = new ReplaySubject<SomeCards[]>(1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this method accepts the property to order by. In our example, this would be priority | |
// sortByDesc('priority') | |
sortByDesc(prop: string) { | |
return this.returnedCardsArr.sort((a, b) => a[prop] < b[prop] ? 1 : a[prop] === b[prop] ? 0 : -1); | |
} | |
// also a slightly verbose way of keeping only unique IDs replacing the ones received from the new call - cause the data also might have changed. | |
for (const card of c) { | |
if (!this.uniqueMap.has(card.id)) { | |
this.uniqueMap.set(card.id, true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private snapshotWatchers: Array<() => void> = []; | |
private syncRequest: Partial<ObservablePaginatedQuery>; | |
private syncCards() { | |
// assume some code here to initialise variables, create a service instance et al | |
// syncRequest is a class variable | |
this.syncRequest = WatchPaginatedCards(); | |
this.syncRequest.cards.pipe().subscribe( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I updated the interface | |
export interface ObservablePaginatedResult { | |
cards: Observable<Array<SomeCards>>; | |
nextPage: IterableIterator<() => void>; // the method returned by iterator should be called to stop listening for changes on this page | |
} | |
public WatchPaginatedCards(pageSize: number = this.DefaultPageSize): <ObservablePaginatedQuery> { | |
const cards$: ReplaySubject<Array<SomeCards>> = new ReplaySubject<SomeCards[]>(1); |
I hereby claim:
- I am automaticalldramatic on github.
- I am rizwaniqbal (https://keybase.io/rizwaniqbal) on keybase.
- I have a public key ASBIwoVK08YsA2ZKfvShz-SYOLALs9SwVTOdzEDXrSgbtAo
To claim this, I am signing this object:
In your command-line run the following commands:
brew doctor
brew update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
env: flex | |
runtime: go1.12 | |
main: cmd/some-service-name/main.go |
NewerOlder