File tree Expand file tree Collapse file tree 3 files changed +23
-7
lines changed Expand file tree Collapse file tree 3 files changed +23
-7
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @rbxts/proton" ,
3
- "version" : " 0.5.8 " ,
3
+ "version" : " 0.5.9 " ,
4
4
"description" : " Framework for Roblox game development" ,
5
5
"main" : " out/init.lua" ,
6
6
"scripts" : {
Original file line number Diff line number Diff line change 1
- import { LifecycleBehavior , ProtonLifecycle } from "./lifecycle" ;
2
-
3
1
const providerClasses = new Map < new ( ) => unknown , unknown > ( ) ;
4
2
5
3
let started = false ;
6
4
const awaitStartThreads : thread [ ] = [ ] ;
7
-
8
- export const ProtonStart = new ProtonLifecycle < ( ) => void > ( LifecycleBehavior . Concurrent ) ;
5
+ const awaitCallbacks : ( ( ) => void ) [ ] = [ ] ;
9
6
10
7
/**
11
8
* Provider decorator.
@@ -36,8 +33,10 @@ export namespace Proton {
36
33
*/
37
34
export function start ( ) {
38
35
if ( started ) return ;
39
- ProtonStart . fire ( ) ;
40
36
started = true ;
37
+ for ( const callback of awaitCallbacks ) {
38
+ task . spawn ( callback ) ;
39
+ }
41
40
for ( const awaitThread of awaitStartThreads ) {
42
41
task . spawn ( awaitThread ) ;
43
42
}
@@ -62,6 +61,20 @@ export namespace Proton {
62
61
coroutine . yield ( ) ;
63
62
}
64
63
64
+ /**
65
+ * Calls the callback once Proton has fully started.
66
+ * If Proton is already started, the callback will
67
+ * be spawned immediately.
68
+ * @param callback Callback
69
+ */
70
+ export function onStart ( callback : ( ) => void ) {
71
+ if ( started ) {
72
+ task . spawn ( callback ) ;
73
+ return ;
74
+ }
75
+ awaitCallbacks . push ( callback ) ;
76
+ }
77
+
65
78
/**
66
79
* Gets a provider within Proton.
67
80
*
Original file line number Diff line number Diff line change 1
- import { Proton , ProtonStart , Provider } from "./core" ;
1
+ import { Proton } from "./core" ;
2
2
3
3
type LifecycleCallback < T > = ( ...args : Parameters < T > ) => void ;
4
4
@@ -160,3 +160,6 @@ export function Lifecycle<T extends LifecycleCallback<T>>(lifecycle: ProtonLifec
160
160
) ;
161
161
} ;
162
162
}
163
+
164
+ export const ProtonStart = new ProtonLifecycle < ( ) => void > ( LifecycleBehavior . Concurrent ) ;
165
+ Proton . onStart ( ( ) => ProtonStart . fire ( ) ) ;
You can’t perform that action at this time.
0 commit comments