Files
speckle-server/packages/frontend-2/lib/common/helpers/promise.ts
T
Kristaps Fabians Geikins 9427686d42 fix(fe2): various follow mode & thread viewer state sync fixes & improvements (#1595)
* fix(fe2): unfollow on camera move

* WIP new state hydration function

* WIP sync state

* minor cleanup

* fix coloring not being tracked

* fix for post thread close camera pos restore

* supporting duplicate users

* preventing guest commenting + state reset fixes

* fixed guests not receiving viewer comment updates

* post-thread creation opens new thread

* removing gap between 'X is typing' and bubble appearing

* reset filters will also reset colors now

* fixed thread full context

* camera reset fix

* thread reset fix

* fixed router concurrency issues

* followed user avatar fix

* TONS OF DEBUGGING FOR ROUTER QUEUING

* removing queued routing debugging stuff + disabling spotlight cancelation

* WIP async URL updates

* missing authLogger fixed

* fix for broken projection

* fix for bubbles positions not updating correctly

* queued routing cleanup

* fixed spotlight mode disabling unnecessarily

* added back stoplight stop on ctrl

* undid spotlight debugging
2023-05-29 15:20:32 +03:00

37 lines
974 B
TypeScript

export class UninitializedControllablePromiseError extends Error {}
/**
* Create promise that you can reject/resolve outside of the promise's definition
*/
export function createControllablePromise<T>() {
let resolve: Parameters<Promise<T>['then']>[0]
let reject: Parameters<Promise<T>['catch']>[0]
const promise = new Promise<T>((res, rej) => {
resolve = res
reject = rej
})
// wrappers to get around resolve/reject possibly not being set before returning
const resolveWrapper: NonNullable<typeof resolve> = (...args) => {
if (!resolve) {
throw new UninitializedControllablePromiseError('Promise not yet initialized')
}
resolve(...args)
}
const rejectWrapper: NonNullable<typeof reject> = (...args) => {
if (!reject) {
throw new UninitializedControllablePromiseError('Promise not yet initialized')
}
reject(...args)
}
return {
promise,
resolve: resolveWrapper,
reject: rejectWrapper
}
}