Commit 7768ecb
committed
mp.input: remove race conditions when calling
This commit ensures that `input.terminate()` can only close input
requests made by the same script, and prevents any in-transit events
for old input requests from being processed.
Previously, there was no way to guarantee that the input request being
terminated was the one intended; the asynchronous nature of the API
meant that it was always possible (though unlikely) that another client
may have activated its own input request while the termination request
was in transit.
This commit removes the race condition between different scripts calling
`input.terminate()` by sending the script name alongside the termination
message.
In addition, when a script overwrites one of its own input requests,
there may be incoming events still in transit. Some of these events may
have a decent chance of calling `input.terminate()` if they are
processed (e.g., `submit`). This commit avoids this issue by only
processing `closed` requests once a new `input.get()` request is made.input.terminate()
1 parent 103df92 commit 7768ecb
4 files changed
Lines changed: 28 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
976 | 976 | | |
977 | 977 | | |
978 | 978 | | |
979 | | - | |
| 979 | + | |
| 980 | + | |
980 | 981 | | |
981 | 982 | | |
982 | 983 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
654 | 654 | | |
655 | 655 | | |
656 | 656 | | |
| 657 | + | |
657 | 658 | | |
658 | 659 | | |
659 | 660 | | |
660 | 661 | | |
| 662 | + | |
661 | 663 | | |
662 | 664 | | |
| 665 | + | |
| 666 | + | |
663 | 667 | | |
664 | 668 | | |
665 | 669 | | |
| |||
680 | 684 | | |
681 | 685 | | |
682 | 686 | | |
683 | | - | |
684 | 687 | | |
685 | 688 | | |
686 | | - | |
| 689 | + | |
687 | 690 | | |
688 | 691 | | |
689 | | - | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
690 | 695 | | |
691 | 696 | | |
692 | 697 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1659 | 1659 | | |
1660 | 1660 | | |
1661 | 1661 | | |
1662 | | - | |
1663 | | - | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
1664 | 1668 | | |
1665 | 1669 | | |
1666 | 1670 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| 38 | + | |
37 | 39 | | |
38 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
39 | 46 | | |
40 | 47 | | |
41 | 48 | | |
| |||
58 | 65 | | |
59 | 66 | | |
60 | 67 | | |
61 | | - | |
62 | | - | |
63 | | - | |
| 68 | + | |
| 69 | + | |
64 | 70 | | |
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
68 | 74 | | |
69 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
70 | 78 | | |
71 | 79 | | |
72 | 80 | | |
| |||
0 commit comments