Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
orca/src/shared/abort-signal-reason.test.ts at main · tmchow/orca · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
tmchow
orca
Repository navigation
Code
Pull requests
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
orca
/
src
/
shared
/
abort-signal-reason.test.ts
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
75 lines (68 loc) · 3.38 KB
main
Breadcrumbs
orca
/
src
/
shared
/
abort-signal-reason.test.ts
Copy path
Top
File metadata and controls
Code
Blame
75 lines (68 loc) · 3.38 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import
{
getEventListeners
}
from
'node:events'
import
{
expect
,
it
,
vi
}
from
'vitest'
import
{
waitForPromiseWithSignal
}
from
'./abort-signal-reason'
import
{
sharedPromiseSettlementWaiters
}
from
'./promise-settlement-waiters'
it
(
'observes work that rejects after its caller has already canceled'
,
async
(
)
=>
{
const
controller
=
new
AbortController
(
)
const
reason
=
new
Error
(
'Caller canceled'
)
controller
.
abort
(
reason
)
const
work
=
new
Promise
<
never
>
(
(
_resolve
,
reject
)
=>
{
queueMicrotask
(
(
)
=>
reject
(
new
Error
(
'Late filesystem failure'
)
)
)
}
)
await
expect
(
waitForPromiseWithSignal
(
work
,
controller
.
signal
)
)
.
rejects
.
toBe
(
reason
)
await
new
Promise
<
void
>
(
(
resolve
)
=>
setImmediate
(
resolve
)
)
}
)
it
(
'detaches cancelled callers from shared stalled work while another caller waits'
,
async
(
)
=>
{
let
finish
=
(
_value
:
number
)
:
void
=>
{
}
const
work
=
new
Promise
<
number
>
(
(
resolve
)
=>
{
finish
=
resolve
}
)
const
observed
=
vi
.
spyOn
(
work
,
'then'
)
const
anchorController
=
new
AbortController
(
)
const
anchor
=
waitForPromiseWithSignal
(
work
,
anchorController
.
signal
)
for
(
let
index
=
0
;
index
<
100
;
index
+=
1
)
{
const
controller
=
new
AbortController
(
)
const
cancelled
=
waitForPromiseWithSignal
(
work
,
controller
.
signal
)
controller
.
abort
(
new
Error
(
'cancelled'
)
)
await
expect
(
cancelled
)
.
rejects
.
toThrow
(
'cancelled'
)
expect
(
getEventListeners
(
controller
.
signal
,
'abort'
)
)
.
toHaveLength
(
0
)
}
expect
(
observed
)
.
toHaveBeenCalledOnce
(
)
expect
(
sharedPromiseSettlementWaiters
(
work
)
.
waiterCount
)
.
toBe
(
1
)
finish
(
42
)
await
expect
(
anchor
)
.
resolves
.
toBe
(
42
)
expect
(
sharedPromiseSettlementWaiters
(
work
)
.
waiterCount
)
.
toBe
(
0
)
expect
(
getEventListeners
(
anchorController
.
signal
,
'abort'
)
)
.
toHaveLength
(
0
)
}
)
it
(
'observes shared work only once for callers already aborted'
,
async
(
)
=>
{
const
work
=
new
Promise
<
void
>
(
(
)
=>
{
}
)
const
observed
=
vi
.
spyOn
(
work
,
'then'
)
const
signal
=
AbortSignal
.
abort
(
new
Error
(
'cancelled'
)
)
for
(
let
index
=
0
;
index
<
100
;
index
+=
1
)
{
await
expect
(
waitForPromiseWithSignal
(
work
,
signal
)
)
.
rejects
.
toThrow
(
'cancelled'
)
}
expect
(
observed
)
.
toHaveBeenCalledOnce
(
)
expect
(
sharedPromiseSettlementWaiters
(
work
)
.
waiterCount
)
.
toBe
(
0
)
}
)
it
(
'allows synchronous cancellation before a cached settlement is delivered'
,
async
(
)
=>
{
const
work
=
Promise
.
resolve
(
42
)
await
expect
(
waitForPromiseWithSignal
(
work
,
new
AbortController
(
)
.
signal
)
)
.
resolves
.
toBe
(
42
)
const
controller
=
new
AbortController
(
)
const
waiting
=
waitForPromiseWithSignal
(
work
,
controller
.
signal
)
controller
.
abort
(
new
Error
(
'cancelled'
)
)
await
expect
(
waiting
)
.
rejects
.
toThrow
(
'cancelled'
)
await
expect
(
waitForPromiseWithSignal
(
work
,
new
AbortController
(
)
.
signal
)
)
.
resolves
.
toBe
(
42
)
}
)
it
(
'returns work directly when no cancellation was requested'
,
(
)
=>
{
const
work
=
Promise
.
resolve
(
42
)
expect
(
waitForPromiseWithSignal
(
work
)
)
.
toBe
(
work
)
}
)
it
(
'preserves an abort queued between two callers of an already-settled promise'
,
async
(
)
=>
{
const
work
=
Promise
.
resolve
(
42
)
const
first
=
waitForPromiseWithSignal
(
work
,
new
AbortController
(
)
.
signal
)
const
controller
=
new
AbortController
(
)
queueMicrotask
(
(
)
=>
controller
.
abort
(
new
Error
(
'cancelled before this caller could read'
)
)
)
const
second
=
waitForPromiseWithSignal
(
work
,
controller
.
signal
)
await
expect
(
first
)
.
resolves
.
toBe
(
42
)
await
expect
(
second
)
.
rejects
.
toThrow
(
'cancelled before this caller could read'
)
}
)
You can’t perform that action at this time.