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

perf: remove extra Promise wrapper for value in fromPromise and toPromise #172

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/three-dogs-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'wonka': patch
---

Remove extra `Promise` wrapper for `value` in `fromPromise` and `toPromise`
2 changes: 1 addition & 1 deletion src/sinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export function toPromise<T>(source: Source<T>): Promise<T> {
let value: T | void;
source(signal => {
if (signal === SignalKind.End) {
Promise.resolve(value!).then(resolve);
resolve(value!);
} else if (signal.tag === SignalKind.Start) {
(talkback = signal[0])(TalkbackKind.Pull);
} else {
Expand Down
6 changes: 2 additions & 4 deletions src/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,8 @@ export function fromDomEvent(element: HTMLElement, event: string): Source<Event>
export function fromPromise<T>(promise: Promise<T>): Source<T> {
return make(observer => {
promise.then(value => {
Promise.resolve(value).then(() => {
observer.next(value);
observer.complete();
});
observer.next(value);
observer.complete();
});
return teardownPlaceholder;
});
Expand Down
Loading