Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
duniter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
typescript
duniter
Merge requests
!1229
1.6 into DockerBuild
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
1.6 into DockerBuild
1.6
into
DockerBuild
Overview
0
Commits
16
Pipelines
0
Changes
32
Merged
Éloïs
requested to merge
1.6
into
DockerBuild
7 years ago
Overview
0
Commits
16
Pipelines
0
Changes
32
0
0
Merge request reports
Compare
DockerBuild
DockerBuild (base)
and
latest version
latest version
e843c8e0
16 commits,
7 years ago
32 files
+
696
−
958
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
32
app/modules/prover/lib/PowWorker.ts
0 → 100644
+
95
−
0
View file @ e843c8e0
Edit in single-file editor
Open in Web IDE
import
{
Querable
}
from
"
./permanentProver
"
const
querablep
=
require
(
'
querablep
'
)
/*********
*
* PoW worker
* ----------
*
* Its model is super simple: we ask him to find a proof, and we can wait for it.
* Eventually, we can tell him to cancel his proof, which makes it answer `null` as proof value.
*
* The worker also provides two properties:
*
* - `worker.online`: a promise which is resolved when the worker gets « online » for the first time
* - `worker.exit`: a promise which is resolved when the worker exits (which occurs when the worker is being closed or killed)
*
********/
export
class
PowWorker
{
private
onlinePromise
:
Promise
<
void
>
private
onlineResolver
:()
=>
void
private
exitPromise
:
Promise
<
void
>
private
exitResolver
:()
=>
void
private
proofPromise
:
Querable
<
{
message
:
{
answer
:
any
}}
|
null
>
private
proofResolver
:(
proof
:{
message
:
{
answer
:
any
}}
|
null
)
=>
void
private
messageHandler
:((
worker
:
any
,
msg
:
any
)
=>
void
)
constructor
(
private
nodejsWorker
:
any
,
private
onPowMessage
:(
message
:
any
)
=>
void
,
private
onlineHandler
:()
=>
void
,
private
exitHandler
:(
code
:
any
,
signal
:
any
)
=>
void
)
{
// Handle "online" promise
this
.
onlinePromise
=
new
Promise
(
res
=>
this
.
onlineResolver
=
res
)
nodejsWorker
.
on
(
'
online
'
,
()
=>
{
this
.
onlineHandler
()
this
.
onlineResolver
()
})
// Handle "exit" promise
this
.
exitPromise
=
new
Promise
(
res
=>
this
.
exitResolver
=
res
)
nodejsWorker
.
on
(
'
exit
'
,
(
code
:
any
,
signal
:
any
)
=>
{
this
.
exitHandler
(
code
,
signal
)
this
.
exitResolver
()
})
nodejsWorker
.
on
(
'
message
'
,
(
message
:
any
)
=>
{
if
(
message
)
{
this
.
onPowMessage
(
message
)
}
if
(
this
.
proofPromise
&&
message
.
uuid
&&
!
this
.
proofPromise
.
isResolved
()
&&
this
.
proofResolver
)
{
const
result
:{
message
:
{
answer
:
any
}}
|
null
=
message
?
{
message
}
:
null
this
.
proofResolver
(
result
)
}
})
}
get
online
()
{
return
this
.
onlinePromise
}
get
exited
()
{
return
this
.
exitPromise
}
get
pid
()
{
return
this
.
nodejsWorker
.
process
.
pid
}
askProof
(
commandMessage
:{
uuid
:
string
,
command
:
string
,
value
:
any
})
{
this
.
proofPromise
=
querablep
(
new
Promise
<
{
message
:
{
answer
:
any
}}
|
null
>
(
res
=>
this
.
proofResolver
=
res
))
this
.
nodejsWorker
.
send
(
commandMessage
)
return
this
.
proofPromise
}
sendConf
(
confMessage
:{
command
:
string
,
value
:
any
})
{
this
.
nodejsWorker
.
send
(
confMessage
)
}
sendCancel
()
{
this
.
nodejsWorker
.
send
({
command
:
'
cancel
'
})
}
kill
()
{
this
.
nodejsWorker
.
kill
()
}
}
\ No newline at end of file
Loading