-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
conservative updates for await blocks
- Loading branch information
1 parent
fa440fd
commit 393757d
Showing
4 changed files
with
71 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { sleep } from './sleep.js'; | ||
|
||
export default { | ||
html: ` | ||
<p>loading...</p> | ||
`, | ||
|
||
test({ assert, component, target }) { | ||
return sleep(50).then(() => { | ||
assert.htmlEqual(target.innerHTML, ` | ||
<p>the answer is 42</p> | ||
<p>count: 1</p> | ||
`); | ||
}); | ||
} | ||
}; |
19 changes: 19 additions & 0 deletions
19
test/runtime/samples/await-conservative-update/main.svelte
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script> | ||
import { sleep } from './sleep.js'; | ||
let count = 0; | ||
const get_promise = () => { | ||
return sleep(10).then(() => { | ||
count += 1; | ||
return 42; | ||
}); | ||
}; | ||
</script> | ||
|
||
{#await get_promise()} | ||
<p>loading...</p> | ||
{:then value} | ||
<p>the answer is {value}</p> | ||
<p>count: {count}</p> | ||
{/await} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export let stopped = false; | ||
|
||
export const stop = () => stopped = true; | ||
|
||
export const sleep = ms => new Promise(f => { | ||
if (stopped) return; | ||
setTimeout(() => { | ||
if (stopped) return; | ||
f(); | ||
}, ms); | ||
}); |