@@ -5,10 +5,10 @@ use std::{
55 mem:: { ManuallyDrop , MaybeUninit } ,
66 ops:: Deref ,
77 pin:: Pin ,
8- sync:: Arc ,
98} ;
109
11- use isoprenoid:: runtime:: { Propagation , SignalsRuntimeRef } ;
10+ use futures_channel:: oneshot;
11+ use isoprenoid_bound:: runtime:: { Propagation , SignalsRuntimeRef } ;
1212use pin_project:: pin_project;
1313
1414use crate :: {
@@ -510,19 +510,19 @@ impl<T: ?Sized, SR: ?Sized + SignalsRuntimeRef> Subscription<T, Opaque, SR> {
510510 async {
511511 let sub = Subscription :: computed_with_runtime ( select_fn_pin, runtime. clone ( ) ) ;
512512 {
513- let once = async_lock :: Mutex :: new ( ( ) ) ;
514- let mut lock = Some ( once . try_lock ( ) . expect ( "unreachable" ) ) ;
513+ let ( notify_ready , ready ) = oneshot :: channel ( ) ;
514+ let mut notify = Some ( notify_ready ) ;
515515 signals_helper ! {
516516 let effect = effect_with_runtime!( {
517517 let sub = & sub;
518518 move || {
519519 if !predicate_fn_pin( & * * sub. read_dyn( ) ) {
520- drop ( lock . take( ) ) ;
520+ notify . take( ) . expect ( "Reached only once." ) . send ( ( ) ) ;
521521 }
522522 }
523523 } , drop, runtime) ;
524524 }
525- once . lock ( ) . await ;
525+ ready . await ;
526526 }
527527 sub
528528 }
@@ -597,24 +597,21 @@ impl<T: ?Sized, SR: ?Sized + SignalsRuntimeRef> Subscription<T, Opaque, SR> {
597597 SR : ' a ,
598598 {
599599 async {
600- // It's actually possible to avoid the `Arc` here, with a tri-state atomic or another `Once`,
601- // since the closure is guaranteed to run when the subscription is created.
602- // However, that would be considerably trickier code.
603- let once = Arc :: new ( async_lock:: Mutex :: < ( ) > :: new ( ( ) ) ) ;
604- let mut lock = Some ( once. try_lock_arc ( ) . expect ( "unreachable" ) ) ;
600+ let ( notify_initialized, initialized) = oneshot:: channel ( ) ;
601+ let mut notify_initialized = Some ( notify_initialized) ;
605602 let sub = Subscription :: folded_with_runtime (
606603 MaybeUninit :: uninit ( ) ,
607604 {
608605 move |value| {
609606 let next = fn_pin ( ) ;
610607 if predicate_fn_pin ( & next) {
611- match lock . take ( ) {
608+ match notify_initialized . take ( ) {
612609 None => {
613610 * unsafe { value. assume_init_mut ( ) } = next;
614611 }
615- Some ( lock ) => {
612+ Some ( notify_initialized ) => {
616613 value. write ( next) ;
617- drop ( lock ) ;
614+ notify_initialized . send ( ( ) ) ;
618615 }
619616 }
620617 Propagation :: Propagate
@@ -625,7 +622,7 @@ impl<T: ?Sized, SR: ?Sized + SignalsRuntimeRef> Subscription<T, Opaque, SR> {
625622 } ,
626623 runtime,
627624 ) ;
628- once . lock ( ) . await ;
625+ initialized . await ;
629626
630627 unsafe { assume_init_subscription ( sub) }
631628 }
@@ -689,23 +686,20 @@ impl<T: ?Sized, SR: ?Sized + SignalsRuntimeRef> Subscription<T, Opaque, SR> {
689686 SR : ' a ,
690687 {
691688 async {
692- // It's actually possible to avoid the `Arc` here, with a tri-state atomic or another `Once`,
693- // since the closure is guaranteed to run when the subscription is created.
694- // However, that would be considerably trickier code.
695- let once = Arc :: new ( async_lock:: Mutex :: new ( ( ) ) ) ;
696- let mut lock = Some ( once. try_lock_arc ( ) . expect ( "unreachable" ) ) ;
689+ let ( notify_initialized, initialized) = oneshot:: channel ( ) ;
690+ let mut notify_initialized = Some ( notify_initialized) ;
697691 let sub = Subscription :: folded_with_runtime (
698692 MaybeUninit :: uninit ( ) ,
699693 {
700694 move |value| {
701695 if let Some ( next) = fn_pin ( ) {
702- match lock . take ( ) {
696+ match notify_initialized . take ( ) {
703697 None => {
704698 * unsafe { value. assume_init_mut ( ) } = next;
705699 }
706- Some ( lock ) => {
700+ Some ( notify_initialized ) => {
707701 value. write ( next) ;
708- drop ( lock ) ;
702+ notify_initialized . send ( ( ) ) ;
709703 }
710704 }
711705 Propagation :: Propagate
@@ -716,7 +710,7 @@ impl<T: ?Sized, SR: ?Sized + SignalsRuntimeRef> Subscription<T, Opaque, SR> {
716710 } ,
717711 runtime,
718712 ) ;
719- once . lock ( ) . await ;
713+ initialized . await ;
720714
721715 unsafe { assume_init_subscription ( sub) }
722716 }
0 commit comments