Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
fluttertpc_get
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Jonatas
2020-11-09 20:05:04 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
261a4767b9ccd41c89b630b39461fdce413b7350
261a4767
1 parent
281ec40f
improve getstream security
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
17 deletions
lib/get_rx/src/rx_stream/get_stream.dart
lib/get_rx/src/rx_workers/rx_workers.dart
lib/get_rx/src/rx_stream/get_stream.dart
View file @
261a476
...
...
@@ -62,12 +62,24 @@ You cannot ${isClosed ? "close" : "add events to"} a closed stream.''';
class
LightListenable
<
T
>
{
List
<
LightSubscription
<
T
>>
_onData
=
<
LightSubscription
<
T
>>[];
void
removeSubscription
(
LightSubscription
<
T
>
subs
)
{
_onData
.
remove
(
subs
);
bool
_isBusy
=
false
;
FutureOr
<
bool
>
removeSubscription
(
LightSubscription
<
T
>
subs
)
async
{
if
(!
_isBusy
)
{
return
_onData
.
remove
(
subs
);
}
else
{
await
Future
.
delayed
(
Duration
.
zero
);
return
_onData
.
remove
(
subs
);
}
}
void
addSubscription
(
LightSubscription
<
T
>
subs
)
{
_onData
.
add
(
subs
);
FutureOr
<
void
>
addSubscription
(
LightSubscription
<
T
>
subs
)
async
{
if
(!
_isBusy
)
{
return
_onData
.
add
(
subs
);
}
else
{
await
Future
.
delayed
(
Duration
.
zero
);
return
_onData
.
add
(
subs
);
}
}
int
get
length
=>
_onData
?.
length
;
...
...
@@ -75,23 +87,20 @@ class LightListenable<T> {
bool
get
hasListeners
=>
_onData
.
isNotEmpty
;
void
notifyData
(
T
data
)
{
_checkIfDisposed
();
assert
(!
isDisposed
,
'You cannot add data to a closed stream.'
);
_isBusy
=
true
;
for
(
final
item
in
_onData
)
{
if
(
item
.
isPaused
)
{
break
;
}
item
.
_data
?.
call
(
data
);
}
}
void
_checkIfDisposed
()
{
if
(
isDisposed
)
{
throw
'[LightStream] Error: You cannot add events to a closed stream.'
;
}
_isBusy
=
false
;
}
void
notifyError
(
Object
error
,
[
StackTrace
stackTrace
])
{
_checkIfDisposed
();
assert
(!
isDisposed
,
'You cannot add errors to a closed stream.'
);
_isBusy
=
true
;
for
(
final
item
in
_onData
)
{
if
(
item
.
isPaused
)
{
break
;
...
...
@@ -102,19 +111,25 @@ class LightListenable<T> {
item
.
_onDone
?.
call
();
}
}
_isBusy
=
false
;
}
void
notifyDone
()
{
_checkIfDisposed
();
assert
(!
isDisposed
,
'You cannot close a closed stream.'
);
_isBusy
=
true
;
for
(
final
item
in
_onData
)
{
if
(
item
.
isPaused
)
{
break
;
}
item
.
_onDone
?.
call
();
}
_isBusy
=
false
;
}
void
dispose
()
=>
_onData
=
null
;
void
dispose
()
{
_onData
=
null
;
_isBusy
=
null
;
}
bool
get
isDisposed
=>
_onData
==
null
;
}
...
...
lib/get_rx/src/rx_workers/rx_workers.dart
View file @
261a476
...
...
@@ -104,10 +104,8 @@ Worker once<T>(RxInterface<T> listener, WorkerCallback<T> callback,
if
(!
_conditional
(
condition
))
return
;
ref
.
_disposed
=
true
;
ref
.
_log
(
'called'
);
sub
?.
cancel
();
callback
(
event
);
Timer
.
run
(()
{
sub
?.
cancel
();
});
});
ref
=
Worker
(
sub
.
cancel
,
'[once]'
);
return
ref
;
...
...
Please
register
or
login
to post a comment